dotnet / dotnet/wpf

How to Cancel DataGrid Column Drag effect?

Open
#10,528 2 comments 0 reactions 0 assignees View on GitHub
:mailbox_with_no_mail: waiting-author-feedback Question
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.