GridColumnSortInfo Class
Represents an element in a GridColumnSortInfoCollection.
Namespace: DevExpress.XtraGrid.Columns
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
Related API Members
The following members return GridColumnSortInfo objects:
Remarks
Create GridColumnSortInfo objects to add elements to the ColumnView.SortInfo collection. This collection represents an instance of the GridColumnSortInfoCollection type, it maintains the sorted and grouping columns for a View.
By adding elements to the collection you can apply sorting and grouping to specific columns. For this purpose initialize a new GridColumnSortInfo object with a specific column and sort order. Then use the GridColumnSortInfoCollection.Add or GridColumnSortInfoCollection.AddRange method to add the created objects to the collection. The columns will then be sorted automatically using the specified sort order. The order of the columns in the collection is important since this defines the sequence of the sorting operations. First, data is sorted by the column referred to by the first element. then by the second element’s column, etc.
To apply grouping to a column(s) the GridColumnSortInfoCollection.GroupCount property must be set to a positive value. This value defines the number of the columns from the beginning of the collection used to group data. That is, to group data by one column add a GridColumnSortInfo item at the zero position in the collection and set GridColumnSortInfoCollection.GroupCount to 1. Set GridColumnSortInfoCollection.GroupCount to 2 to group data by the first two columns, etc.
Example
The following example shows how to apply sorting and grouping to columns via the ColumnView.SortInfo collection. The columns which will be used to group and sort data are added using the GridColumnSortInfoCollection.ClearAndAddRange method. This method first clears the collection. The method’s integer parameter determines the number of the specified array’s elements that will be used to group data. In this example this parameter is set to 2 and thus the two first elements (CategoryID and SupplierID) will be used to group data. The third element (ProductName) refers to the column against which only sorting is applied.
using DevExpress.Data;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
// ...
GridView view = gridControl1.MainView as GridView;
GridColumnSortInfo [] sortInfo = {
new GridColumnSortInfo(view.Columns["CategoryID"], ColumnSortOrder.Ascending),
new GridColumnSortInfo(view.Columns["SupplierID"], ColumnSortOrder.Descending),
new GridColumnSortInfo(view.Columns["ProductName"], ColumnSortOrder.Ascending)
};
view.SortInfo.ClearAndAddRange(sortInfo, 2);