我试图通过挂钩 DataGrid 的SelectedCellsChanged
事件来阻止用户在多列上进行单元格选择。
但是,出于某种原因,我的代码表现得有些奇怪。
这是我的代码:
private void chartDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
foreach (DataGridCellInfo cell in e.AddedCells)
{
// If a selected cell is within a different column than the first selected cell, undo the selection (to prevent selections from crossing multiple columns)
if (cell.Column != e.AddedCells[0].Column)
this.chartDataGrid.SelectedCells.Remove(cell);
}
}
谁能告诉我我在这里缺少什么?