Home Forums WinForms controls Xceed Grid for WinForms Sorting of Grid Reply To: Sorting of Grid

User (Old forums)
Member
Post count: 23064

Do you need this column for the user, or is it only internally in your application that you need it?  If it is only internally, instead of using the an index column, you could use the sorted DataRows list, and retrieve the top 20 rows from it, and do what you need with the rows.

e.g.: 

ReadOnlyDataRowList list = gridControl1.GetSortedDataRows( true );

for( int i = 0; i < 20; i++ )

{

    Xceed.Grid.

DataRow row = list[ i ];

    System.Diagnostics.

Debug.WriteLine( row.Cells[ “SomeColumn” ].Value.ToString() );

}

 

If you absolutely need the index column, then I see no other way then to loop through all the rows and change the index column value of each row accordingly.  Again you can use the sorted DataRow list.

e.g.:

ReadOnlyDataRowList list = gridControl1.GetSortedDataRows( true );

for( int i = 0; i < list.Count; i++ )

{

    list[ i ].Cells[ “IndexColumn” ].Value = ( i + 1 ).ToString();

}

Imported from legacy forums. Posted by André (had 915 views)