Skip to main content

GridColumnSortInfoCollection.ClearAndAddRange(GridColumnSortInfo[], Int32) Method

Clears the collection, then adds the specified objects to it and sets how many columns are used to group data.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v23.2.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

public void ClearAndAddRange(
    GridColumnSortInfo[] sortInfos,
    int groupCount
)

Parameters

Name Type Description
sortInfos GridColumnSortInfo[]

An array of GridColumnSortInfo objects to add to the collection.

groupCount Int32

An integer value specifying how many columns are used to group data.

Remarks

The ClearAndAddRange method clears the current collection and then adds the specified GridColumnSortInfo objects to this collection.

Then the GridColumnSortInfoCollection.GroupCount property is initialized with the groupCount parameter’s value. It specifies the number of columns from the beginning of the current collection used to group data. All the subsequent columns will be used only to sort data. Thus if groupCount is set to 0 all the columns referred to by the collection’s elements will be used to sort data, none of them will be used for grouping.

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);
See Also