Xceed Grid for WinForms v4.3 Documentation
How to retrieve the DataRows in their sorted order

Welcome to Xceed Grid for WinForms v4.3 > Task-Based Help > Rows > How to retrieve the DataRows in their sorted order

A list of all the DataRows contained within the grid can be retrieved using the grid's collection of DataRows; however, the list returned will contain the DataRows in the order that they are found in the data source. If you want to retrieve the DataRows in the order that they are sorted in the grid, then you will need to use the grid's GetSortedDataRows method. 

The GetSortedDataRows method also allows you to retrieve the DataRows recursively depending on the value of its recursive parameter. If the grid does not contain any groups, then setting the recursive parameter to true or false will have the same result: all the DataRows will be retrieved. If the grid contains groups, then setting the recursive parameter to false will result in no DataRows being returned since the DataRows are contained within the groups. Setting the recursive parameter to true (in the case where the grid contains groups) will result in all the DataRows being returned. 

It is also possible to retrieve the DataRows of a specific group using the group's GetSortedDataRows method.

Demonstration

The following example demonstrates how to retrieve a list of all the DataRows in the grid in the order that they are sorted. Because we are setting the recursive parameter of the GetSortedDataRows method to true, all DataRows, event those contained within groups, will be retrieved.

VB.NET Copy Code

Dim rows As Xceed.Grid.Collections.ReadOnlyDataRowList = GridControl1.GetSortedDataRows( True )
Dim row As Xceed.Grid.DataRow 

For Each row in rows
  ListBox1.Items.Add( "Row #" + row.Index.ToString() + " : sort position " +  _
                       rows.IndexOf( row ).ToString() )
Next row

C# Copy Code

Xceed.Grid.Collections.ReadOnlyDataRowList rows = gridControl1.GetSortedDataRows( true ); 

foreach( Xceed.Grid.DataRow row in rows )
{
  listBox1.Items.Add( "Row #" + row.Index.ToString() + " : sort position " +  
                      rows.IndexOf( row ).ToString() );
}