If we click on a field in the XamDataGrid UI control, the records are sorted by that field, I want the order of the records' indices after sorting.
Let grid1 be an instance of XamDataGrid bidden to a datasource. After sorting by a field when I execute the following code
foreach (Record record in grid1.Records)
{
System.Diagnostics.Debug.WriteLine(record.Index);
}
Debug Output:
0
1
2
3
.
.
.
Which is not the sorted order. I tried record.VisibleIndex as well but it also gives the same result.
Is there a way to get the indices' order of the records which the user is currently seeing?
This can be achieving by using the
DataRecord.DataItemIndexproperty. It returns the associated index in the underlying data source:Take to account, that the record numbering in the
XamDataGridis starting from1, but index is starting from0.