GridColumn.SortOrder Property

Gets or sets the column's sort order.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

[DXCategory("Data")]
[DefaultValue(ColumnSortOrder.None)]
[XtraSerializablePropertyId(2)]
public ColumnSortOrder SortOrder { get; set; }
<DXCategory("Data")>
<DefaultValue(ColumnSortOrder.None)>
<XtraSerializablePropertyId(2)>
Public Property SortOrder As ColumnSortOrder

Property Value

Type Default Description
ColumnSortOrder

None

A ColumnSortOrder enumeration value specifying the column's sort order.

Remarks

Read the SortOrder property value to determine which sort order is currently applied to the column. Assign a value to this property to sort data by the current column's values. Note that any previous sorting is not cleared when changing the SortOrder property value. The new sort order applies an additional sorting condition to that previously applied. The newly sorted column is added to the ColumnView.SortedColumns collection as the result. Its index within the collection can be obtained using the GridColumn.SortIndex property.

The GridColumn.SortMode property specifies how the column's data is sorted (by display text, edit values or using a custom sorting algorithm).

To clear the sorting applied previously, call the View's ColumnView.ClearSorting method.

If you need to change the SortOrder property value in the form's Load event handler, you should call the GridControl.ForceInitialize method in advance.

To learn more about sorting, see the Sorting in Code topic.

Examples

The following example sorts data by two columns in a Grid View. The code is enclosed within calls to the ColumnView.BeginDataUpdate and BaseView.EndDataUpdate methods. This speeds up performance by sorting the data only once, after the BaseView.EndDataUpdate method is called.

    gridView1.BeginDataUpdate();
    try {
        gridView1.ClearSorting();
        gridView1.Columns["Trademark"].SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
        gridView1.Columns["Model"].SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
    }
    finally {
        gridView1.EndDataUpdate();
    }
See Also