Articles in this section
Category / Section

How to skip the sorting when group the columns in WPF DataGrid (SfDataGrid) ?

1 min read

WPF DataGrid (SfDataGrid) sorts the column while grouping. You can group the column without allowing it to sort by removing the grouped columns from SortDescriptions.

this.dataGrid.Loaded += OnDataGrid_Loaded;
 
private void OnDataGrid_Loaded(object sender, RoutedEventArgs e)
{
    this.dataGrid.View.CurrentChanged += OnView_CurrentChanged;
}
 
private void OnView_CurrentChanged(object sender, EventArgs e)
{
    var groupColumn = dataGrid.View.SortDescriptions.FirstOrDefault(x => x.PropertyName == "ProductName");
 
    if (dataGrid.SortColumnDescriptions.FirstOrDefault(x => x.ColumnName == "ProductName") != null)
        dataGrid.View.SortDescriptions.Remove(groupColumn);
}

 

SfDataGrid grouped by ProductName without sorting

 

View WPF DataGrid Sorting Demo in GitHub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied