wpf-devexpress-dot-xpf-dot-grid-36e7b533.md
Represents an element in the GridControl.SortInfo collection.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public class GridSortInfo :
DependencyObject,
IColumnInfo,
IMergeWithPreviousGroup
Public Class GridSortInfo
Inherits DependencyObject
Implements IColumnInfo,
IMergeWithPreviousGroup
The GridControl.SortInfo collection maintains the sorted and grouped columns. Individual elements contained within this collection are represented by the GridSortInfo class. A GridSortInfo object specifies a column (GridSortInfo.FieldName), its sort order (GridSortInfo.SortOrder) and a grouping flag, which is set to true if grouping is applied to this column.
Adding elements to the GridControl.SortInfo collection applies sorting or grouping by specific columns. Removing elements from this collection clears sorting/grouping by the corresponding column.
The GridSortInfo objects that refer to the columns used to group data always come first in the collection. The number of such elements is specified by the GridSortInfoCollection.GroupCount property. The subsequent elements in the collection refer to the columns used for data sorting only.
To learn more, see Sorting in Code.
This example shows how to apply data sorting and grouping in XAML.
Since group rows are always sorted, data grouping requires data sorting. Sorting applied to group columns takes priority over other columns. To group data by one column in XAML, do the following:
GridSortInfo object and specify its GridSortInfo.FieldName and GridSortInfo.SortOrder properties. The GridSortInfo.FieldName property specifies the grouping column by its field name.GridSortInfo object to the grid’s GridControl.SortInfo collection. This object must be the first element in this collection.The image below shows the result:
using System.ComponentModel;
using DevExpress.Xpf.Grid;
public Window1() {
InitializeComponent();
grid.DataSource =
new dsNwindProductsTableAdapters.ProductsTableAdapter().GetData();
CreateSortInfo(grid);
}
private void CreateSortInfo(GridControl grid) {
grid.SortInfo.Add(new GridSortInfo("UnitPrice", ListSortDirection.Descending));
grid.SortInfo.Add(new GridSortInfo("ProductName", ListSortDirection.Ascending));
grid.GroupCount = 1;
}
<dxg:GridControl x:Name="grid" GroupCount="1">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="ProductName"/>
<dxg:GridColumn FieldName="UnitPrice"/>
<dxg:GridColumn FieldName="UnitsOnOrder" Header="Units On Order"/>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" ShowGroupedColumns="False"/>
</dxg:GridControl.View>
<dxg:GridControl.SortInfo>
<dxg:GridSortInfo FieldName="UnitPrice" SortOrder="Descending"/>
<dxg:GridSortInfo FieldName="ProductName" SortOrder="Ascending"/>
</dxg:GridControl.SortInfo>
</dxg:GridControl>
Object DispatcherObject DependencyObject GridSortInfo
See Also