Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove wpf grid sort arrow after clearing sort descriptions

I click on a grid header to sort a column and then click a "Reset" button to clear the sort descriptions through its collection view. But the sort arrow icon still persists in the header. How to remove it?

like image 992
John Avatar asked Mar 23 '11 07:03

John


People also ask

What is the difference between grid and DataGrid in WPF?

A Grid is a control for laying out other controls on the form (or page). A DataGrid is a control for displaying tabular data as read from a database for example.


2 Answers

I came across this question whilst trying to work out how to clear the sort from the grid completely. Thanks to [krishnaaditya] for the answering how to clear the sort arrow from the header.

using System.Windows.Data;
using System.ComponentModel;

ICollectionView view = CollectionViewSource.GetDefaultView(resultsGrid.ItemsSource);
if (view != null && view.SortDescriptions.Count > 0)
{
    view.SortDescriptions.Clear();
    foreach (DataGridColumn column in resultsGrid.Columns)
    {
        column.SortDirection = null;
    }
}
like image 87
Andrea Avatar answered Sep 25 '22 09:09

Andrea


simple solution i can think of is

foreach (DataGridColumn column in DataGridView.Columns)
{
    column.SortDirection = null;
}
like image 31
krishnaaditya Avatar answered Sep 24 '22 09:09

krishnaaditya