Sorting in Code
- 2 minutes to read
#Sorting
The following methods and properties can be used to sort data.
A column's ColumnBase.SortOrder property specifies a column's sort order. Set it to ColumnSortOrder.Ascending or ColumnSortOrder.Descending.
grid.Columns["ProductName"].SortOrder = ColumnSortOrder.Ascending;
- Set a column's ColumnBase.SortIndex property to a non-negative value. This automatically sorts its values in ascending order.
- Use the grid's GridControl.SortBy method.
Create a new instance of the GridSortInfo class, specify its GridSortInfo.FieldName and GridSortInfo.SortOrder properties, and add it to the grid's GridControl.SortInfo collection.
#Unsorting
To unsort data by the values of a single column, do one of the following:
- Set the column's ColumnBase.SortOrder property to ColumnSortOrder.None.
- Set the column's ColumnBase.SortIndex property to -1.
Use the grid's GridControl.SortBy method.
grid.SortBy(grid.Columns["ProductName"], ColumnSortOrder.None);
Remove the corresponding GridSortInfo object from the GridControl.SortInfo collection.
grid.SortInfo.Remove(grid.SortInfo["ProductName"]);
To clear sorting applied to a grid, use the DataControlBase.ClearSorting method.
NOTE
If grouping is applied, the Data
#Sorting Events
When sorting data, the grid does the following.
- Raises the GridControl.StartSorting event.
- Sorts data.
- Raises the GridControl.EndSorting event.
NOTE
Group rows are always sorted. The Start