windowsforms-devexpress-dot-xtragrid-dot-columns-dot-gridcolumn-f1a380cc.md
Gets or sets the column’s sort order.
Namespace : DevExpress.XtraGrid.Columns
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DefaultValue(ColumnSortOrder.None)]
[DXCategory("Data")]
[XtraSerializablePropertyId(2)]
public ColumnSortOrder SortOrder { get; set; }
<DXCategory("Data")>
<DefaultValue(ColumnSortOrder.None)>
<XtraSerializablePropertyId(2)>
Public Property SortOrder As ColumnSortOrder
| 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.
|
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.
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();
}
gridView1.BeginDataUpdate()
Try
gridView1.ClearSorting()
gridView1.Columns("Trademark").SortOrder = DevExpress.Data.ColumnSortOrder.Ascending
gridView1.Columns("Model").SortOrder = DevExpress.Data.ColumnSortOrder.Ascending
Finally
gridView1.EndDataUpdate()
End Try
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.
winforms-grid-always-sort-by-column/CS/Form1.cs#L44
{
if (column.SortOrder != DevExpress.Data.ColumnSortOrder.Ascending || column.SortIndex != view.SortInfo.Count - 1)
{
winforms-grid-reorder-tileview-cards-sql/CS/Reorder/Form1.cs#L16
// Sort by the "IndexInGroup" column
colIndexInGroup.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
gridControl1.DataSource = DataHelper.GetData();
winforms-reporting-create-grid-based-report/CS/ConvertGridToReportExample/XtraReport1.cs#L44
GroupField gField;
if (gridColumn.SortOrder == ColumnSortOrder.Ascending)
gField = new GroupField(gridColumn.FieldName, XRColumnSortOrder.Ascending);
winforms-grid-move-focused-row-up-down/CS/Form1.cs#L197
gridView1.PopulateColumns();
gridView1.Columns[OrderFieldName].SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
gridView1.OptionsCustomization.AllowSort = false;
winforms-grid-always-sort-by-column/VB/Form1.vb#L38
If checkEdit1.Checked Then
If column.SortOrder <> DevExpress.Data.ColumnSortOrder.Ascending OrElse column.SortIndex <> view.SortInfo.Count - 1 Then
column.SortIndex = view.SortInfo.Count
winforms-grid-reorder-tileview-cards-sql/VB/Reorder/Form1.vb#L16
' Sort by the "IndexInGroup" column
colIndexInGroup.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending
gridControl1.DataSource = DataHelper.GetData()
winforms-reporting-create-grid-based-report/VB/ConvertGridToReportExample/XtraReport1.vb#L42
Dim gField As GroupField
If gridColumn.SortOrder = ColumnSortOrder.Ascending Then
gField = New GroupField(gridColumn.FieldName, XRColumnSortOrder.Ascending)
winforms-grid-move-focused-row-up-down/VB/Form1.vb#L195
gridView1.PopulateColumns()
gridView1.Columns(OrderFieldName).SortOrder = DevExpress.Data.ColumnSortOrder.Ascending
gridView1.OptionsCustomization.AllowSort = False
See Also