Back to Devexpress

ColumnView.SortInfo Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-7fcf83ed.md

latest5.6 KB
Original Source

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.v25.2.dll

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

Declaration

csharp
[Browsable(false)]
[XtraSerializableProperty(XtraSerializationFlags.UseAssign | XtraSerializationFlags.LoadOnly, 1000)]
[XtraSerializablePropertyId(3)]
public virtual GridColumnSortInfoCollection SortInfo { get; }
vb
<Browsable(False)>
<XtraSerializableProperty(XtraSerializationFlags.UseAssign Or XtraSerializationFlags.LoadOnly, 1000)>
<XtraSerializablePropertyId(3)>
Public Overridable ReadOnly Property SortInfo As GridColumnSortInfoCollection

Property Value

TypeDescription
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.

csharp
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);
vb
Imports DevExpress.Data
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
' ...
Dim view As GridView = gridControl1.MainView
Dim sortInfo As GridColumnSortInfo() = { _
        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

SortMode

SortOrder

GroupIndex

Sort Data in Code

Summaries

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace