How to remove wpf grid sort arrow after clearing sort descriptions

一个人想着一个人 提交于 2020-01-03 13:20:11

问题


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?


回答1:


simple solution i can think of is

foreach (DataGridColumn column in DataGridView.Columns)
{
    column.SortDirection = null;
}



回答2:


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;
                                 };
                             }


来源:https://stackoverflow.com/questions/5401912/how-to-remove-wpf-grid-sort-arrow-after-clearing-sort-descriptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!