[英]Turn DataGridColumn sorting off
我的DataGrid再次出现问题...这次:编辑单元格时如何关闭排序?
例如:
我在最后加上标记的“ A”,由于列已排序,因此它跳到了顶部。 但它应该留在按钮上。 如果对设置文件进行排序(在Visual Studio中),则其工作原理与我想要的完全相同。 您可以自己尝试,这是VS中的相同示例:
我试图重置SortDirection
,但无法正常工作:
private void dgVATINS_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
foreach (DataGridColumn col in dgVATINS.Columns)
{
col.SortDirection = null;
}
}
Helper.SetGridViewSortState(this.dgv,DataGridViewColumnSortMode.NotSortable); 请尝试这个
找到一个解决方案:
/// <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;
};
}
}
并从ObservableCollection<T>
将事件处理程序添加到CollectionChanged
事件
void VATINS_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
ResetSorting();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.