How to Cancel DataGrid Column Drag effect?
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
In the WPF DataGrid control, I use CanUserReorder=True to pin the first three columns and allow columns 4-10 to be reordered by dragging, and want to prevent them from being dragged onto the first three columns. Therefore, I handle e.Cancel=true in the DataGrid_ColumnReordering event. However, the e.NewDisplayIndex property does not exist. How should I achieve the desired effect? The code is as follows:
private void DataGrid_ColumnReordering(object sender, DataGridColumnReorderingEventArgs e)
{
int fixedColumnCount = 3;
DataGridColumn draggedColumn = e.Column;
// but have no e.NewDisplayIndex !!!
if (draggedColumn.CanUserReorder && e.NewDisplayIndex < fixedColumnCount)
{
e.Cancel = true;
}
}
Contributor guide
Assessment
This issue has not been assessed yet.