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

GridColumn.SortIndex Property

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

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v18.2.dll

Declaration

[DefaultValue(-1)]
[Browsable(false)]
[XtraSerializablePropertyId(2)]
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.

Remarks

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.DefaultDraw();
        e.Cache.DrawString(e.Column.SortIndex.ToString(), e.Appearance.GetFont(), Brushes.Red, new Point(e.Bounds.Right - 20, e.Bounds.Y));
        e.Handled = true;
    }

}

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