GridColumnSortInfoCollection Class

Represents the collection that maintains the sorted and grouping columns for a grid's View.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

[ListBindable(false)]
public class GridColumnSortInfoCollection :
    CollectionBase,
    IEnumerable<GridColumnSortInfo>,
    IEnumerable
<ListBindable(False)>
Public Class GridColumnSortInfoCollection
    Inherits CollectionBase
    Implements IEnumerable(Of GridColumnSortInfo),
               IEnumerable

Related API Members

The following members accept/return GridColumnSortInfoCollection objects:

Remarks

The GridColumnSortInfoCollection class represents the collection that stores the sorted and grouping columns for a View. This collection can be accessed via the ColumnView.SortInfo property. Each element in the collection is represented by a GridColumnSortInfo object which is associated with a specific column and the sort order for this column (ascending or descending). The column's GridColumn.SortMode property determines how the column's values should be sorted (by display text, values or using a custom sorting algorithm).

Adding elements to this collection applies sorting or grouping by specific columns within the associated View. Similarly removing elements from the collection clears sorting/grouping by the corresponding column.

The collection's elements which refer to the columns used to group data always come first in the collection. The number of such elements is specified by the GridColumnSortInfoCollection.GroupCount property. The subsequent elements in the collection refer to the columns used for sorting only. Thus to apply grouping to a specific column, add a new GridColumnSortInfo object (which refers to the required column) at the beginning of the collection and customize the GridColumnSortInfoCollection.GroupCount property (the new element's index should be less than the GridColumnSortInfoCollection.GroupCount value).

To add elements to the collection, the GridColumnSortInfoCollection.AddRange and GridColumnSortInfoCollection.ClearAndAddRange methods can be used.

The order of the elements in the collection determines the order in which data is sorted within the View. First data is sorted by the first element's column, then by the second one, etc.

To apply sorting to a column, the GridColumn.SortOrder property can also be used. This will automatically add a corresponding GridColumnSortInfo object to the ColumnView.SortInfo collection.

Similarly applying grouping to a column via its GridColumn.GroupIndex property automatically adds a corresponding GridColumnSortInfo object at the beginning of the ColumnView.SortInfo collection (among the grouping elements).

Examples

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

Inheritance

Object
CollectionBase
GridColumnSortInfoCollection
See Also