Skip to main content

GridColumn.SortIndex Property

Gets or sets the column’s position among sorted columns.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v23.1.dll

NuGet Package: DevExpress.Win.Grid


public int SortIndex { get; set; }

Property Value

Type Default Description
Int32 -1

The column’s index among sorted columns. -1 if data is not sorted by this column.


Grid Views can sort data by multiple columns. Once a column is sorted, the View automatically adds it to the ColumnView.SortedColumns collection. If no columns were previously sorted, the column becomes the only element in the collection and gets the 0 sort index. If data is sorted by one more column, the new column is appended to the collection and gets the 1 index, etc.

If the column’s SortIndex property value changes from -1 to a non-negative integer, the column is added to the sorted column list. The column’s GridColumn.SortOrder property is automatically set to ColumnSortOrder.Ascending. Inversely, if you set a column’s SortIndex property to -1, data is not sorted by this column.

If a column has been sorted and you want to change its sort order, use the methods from the ColumnView.SortInfo object (for instance, the GridColumnSortInfoCollection.Insert method).

See Sorting in Code to learn more.

The code sample below illustrates how to show the sort index in the header row.

gridView1.CustomDrawColumnHeader += GridView1_CustomDrawColumnHeader;

private void GridView1_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
    if (e.Column != null && e.Column.SortIndex >= 0)
        e.Cache.DrawString(e.Column.SortIndex.ToString(), e.Appearance.GetFont(), Brushes.Red, new Point(e.Bounds.Right - 20, e.Bounds.Y));
        e.Handled = true;

See Also