Skip to main content
A newer version of this page is available. .

ColumnView.SortInfo Property

Provides access to the collection of sorted and grouping columns within the current View.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v18.2.dll

Declaration

[Browsable(false)]
[XtraSerializableProperty(XtraSerializationFlags.UseAssign, 1000)]
[XtraSerializablePropertyId(3)]
public virtual GridColumnSortInfoCollection SortInfo { get; }

Property Value

Type Description
GridColumnSortInfoCollection

A GridColumnSortInfoCollection collection containing information on the sorted and grouping columns within the View.

Remarks

The SortInfo property can be used to apply sorting and grouping to one or more of the columns in the current View. This property represents a collection of GridColumnSortInfo objects. Each such element specifies a column, the sort order and a grouping flag, which is set to true if grouping is applied to this column.

To apply sorting or grouping to a column(s), use the appropriate methods provided by the GridColumnSortInfoCollection class. In most cases you will use the overloads of the GridColumnSortInfoCollection.AddRange and GridColumnSortInfoCollection.ClearAndAddRange methods to apply sorting or grouping. See the GridColumnSortInfoCollection topic for more information.

As in Grid Control version 2 to apply sorting to a column the column’s GridColumn.SortOrder property can still be used. The GridColumn.GroupIndex property is an alternative way to apply grouping to the column.

The column’s GridColumn.SortMode property specifies how the column is sorted (by display text, value or custom sorting).

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SortInfo property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also