Skip to main content

GridColumn.SortOrder Property

Gets or sets the column’s sort order.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v24.1.dll

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

Declaration

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

Property Value

Type Default Description
ColumnSortOrder None

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

Available values:

Name Description
None

No sorting is applied to a column.

Ascending

Sorts the column in ascending order.

Descending

Sorts the columns in descending 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.

Example

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the SortOrder 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