我试图在不使用 shift 键的情况下使用DataGridSortingEvent
这些代码对多列进行排序:
private void dataGridPayables_Sorting(object sender, DataGridSortingEventArgs e)
{
if (e.Column.SortDirection == null)
e.Column.SortDirection = ListSortDirection.Descending;
ListSortDirection sort_direction = (ListSortDirection)e.Column.SortDirection;
dataGridPayables.Items.SortDescriptions.Clear();
dataGridPayables.Items.SortDescriptions.Add
(new SortDescription(e.Column.SortMemberPath, sort_direction));
dataGridPayables.Items.SortDescriptions.Add
(new SortDescription("total_amount", sort_direction));
dataGridPayables.Items.SortDescriptions.Add
(new SortDescription("payment_actual", sort_direction));
dataGridPayables.Items.SortDescriptions.Add
(new SortDescription("status", sort_direction));
e.Column.SortDirection = sort_direction;
dataGridPayables.Items.Refresh();
MessageBox.Show("SORT " + e.Column.SortMemberPath + " " + sort_direction.ToString());
}
我发现数据网格是使用上面的代码排序的,但是当它离开该方法时,C# 再次对它进行排序,只选择了列并且失去了多重排序功能。
请帮忙