GridColumnSortInfoCollection.ClearAndAddRange(GridColumnSortInfo[]) Method
Clears the collection and then adds the specified objects to it.
Namespace: DevExpress.XtraGrid.Columns
Assembly: DevExpress.XtraGrid.v24.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
sortInfos | GridColumnSortInfo[] | An array of GridColumnSortInfo objects to add to the collection. |
Remarks
The ClearAndAddRange method clears the current collection and then adds the specified GridColumnSortInfo objects to it.
An element cannot be added to the collection in specific cases. See the GridColumnSortInfoCollection.Add topic for more information.
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);