我的DataGrid又有问题了.这一次:在编辑单元格时,如何关闭排序?
例如:

我添加标记'A‘的最后一个,它跳到顶部,因为列是排序的。但它应该留在按钮上。如果对设置文件进行排序(在Visual中),它的工作方式与我想要的完全一样。您可以自己尝试,以下是VS中的相同示例:

我试着重置SortDirection,但不起作用:
private void dgVATINS_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
foreach (DataGridColumn col in dgVATINS.Columns)
{
col.SortDirection = null;
}
}发布于 2014-11-14 17:52:12
找到了解决办法:
/// <summary>
/// Resets the sorting.
/// </summary>
public void ResetSorting()
{
ICollectionView view = CollectionViewSource.GetDefaultView(dgVATINS.ItemsSource); // Gets the default view of the DataGrid
if (view != null && view.SortDescriptions.Count > 0)
{
view.SortDescriptions.Clear(); // Clears the sorting
foreach (DataGridColumn column in dgVATINS.Columns)
{
column.SortDirection = null;
};
}
}并从CollectionChanged事件中向ObservableCollection<T>事件添加事件处理程序。
void VATINS_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
ResetSorting();
}发布于 2014-11-14 17:16:55
Helper.SetGridViewSortState(this.dgv,DataGridViewColumnSortMode.NotSortable);请试试这个
https://stackoverflow.com/questions/26934542
复制相似问题