6 Answers, 1 is accepted
The "RowIndex" as you call it, is the index of the respective business object instance in your source collection that is fed to RadGridView.ItemsSource.
Regards,Rossen Hristov
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
![](/forums/images/avatarimages/default.gif)
That is correct.
In fact, row re-ordering is not even an out-of-box functionality provided by the grid. It is custom code in an online example, i.e. it is source code that could be (should be) written by you. You can see what the actual source code does for row reordering in the example where you found row reordering in the first place:
private
void
OnDrop(
object
sender, Telerik.Windows.DragDrop.DragEventArgs e)
{
var draggedItem = DragDropPayloadManager.GetDataFromObject(e.Data,
"DraggedItem"
);
var details = DragDropPayloadManager.GetDataFromObject(e.Data,
"DropDetails"
)
as
DropIndicationDetails;
if
(details ==
null
|| draggedItem ==
null
)
{
return
;
}
if
(e.Effects == DragDropEffects.Move || e.Effects == DragDropEffects.All)
{
((sender
as
RadGridView).ItemsSource
as
IList).Remove(draggedItem);
}
if
(e.Effects != DragDropEffects.None)
{
var collection = (sender
as
RadGridView).ItemsSource
as
IList;
int
index = details.DropIndex < 0 ? 0 : details.DropIndex;
index = details.DropIndex > collection.Count - 1 ? collection.Count : index;
collection.Insert(index, draggedItem);
}
}
Please, try to understand what this source code does and that will answer your questions.
If you want to have property that shows the current index of an object, if I were you I would simply pass the instance of the parent collection to my business object constructor and then create something like this:
public int Index
{
get
{
return this.parentCollection.IndexOf(this);
}
}
The magic method here is the IndexOf method, which does what its name says.
Of course, there are hundreds of other ways to implement this, but this is general .NET stuff and I will leave them to your imagination.
I hope this helps. Regards,
Rossen Hristov
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
![](/forums/images/avatarimages/default.gif)
![](/forums/images/avatarimages/default.gif)
An example of row reordering can be seen in our online Quick Start Framework located here. The name of the example is Row Reorder. I have attached a zip file with the source code files. The sample data is created in another class which is common for many samples and that is why is not in the sample source code.
You should be able locate all of the source code in your local installation of our Quick Start Framework.
I hope this helps.
Rossen Hristov
Telerik
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.