DataGridView.SortBy(String, DataSortOrder, Int32) Method
Sorts data by values of the specified column in the specified order, and places the column at the specified position among the sorted columns.
Namespace: DevExpress.Maui.DataGrid
Assembly: DevExpress.Maui.DataGrid.dll
NuGet Package: DevExpress.Maui.DataGrid
Declaration
public void SortBy(
string fieldName,
DataSortOrder sortOrder = DataSortOrder.Ascending,
int sortIndex = 0
)
Parameters
Name | Type | Description |
---|---|---|
fieldName | String | Specifies the grid’s column name. |
Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
sortOrder | DataSortOrder | Ascending | The sort order. |
sortIndex | Int32 | 0 | The zero-based column’s index among the sorted columns. |
Remarks
Use the SortBy
method to sort data in the grid.
- Single-Column Sorting (Default)
- The grid allows data sorting by a single column only, if the DataGridView.SortMode property is set to Single.
In this case, when you call theSortBy
method, the grid discards the previously applied sorting by another column. - Multi-Column Sorting
- The grid supports multi-column sorting if the DataGridView.SortMode property is set to Multiple.
When you call the
SortBy
method, the grid does not clear the previously applied sorting and uses the new sort order as an additional condition to sort data. ThesortIndex
parameter specifies the column sort sequence.
Another way to sort data in the grid by column values is to use the column’s GridColumn.SortOrder property. To specify the sort sequence applied to multiple columns, use the GridColumn.SortIndex property of these columns.
To specify whether the grid should sort data by cell values or display text, use the GridColumn.SortMode property.
To prevent users from sorting data, use the DataGridView.AllowSort and GridColumn.AllowSort properties.
To cancel sorting, use the DataGridView.ClearSorting method.