How to get the order of the sorted records' indices in Infragistics xamDataGrid?

148 Views Asked by At

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?

1

There are 1 best solutions below

0
Jackdaw On BEST ANSWER

This can be achieving by using the DataRecord.DataItemIndex property. It returns the associated index in the underlying data source:

foreach (DataRecord record in grid1.FieldLayouts.DataPresenter.Records)
{                       
    System.Diagnostics.Debug.WriteLine(record.DataItemIndex);                
}

Take to account, that the record numbering in the XamDataGrid is starting from 1, but index is starting from 0.