我试图阻止用户通过挂钩到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);
}
}
谁能告诉我这里缺少什么?
答案 0 :(得分:0)
好的,我摆脱了这种行为,但偶然发现了新代码的另一个问题,如下所示:
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 != this.chartDataGrid.SelectedCell[0].Column)
this.chartDataGrid.SelectedCells.Remove(cell);
}
}
现在我无法将我的选择扩展到右侧的列(这很好),但我仍然可以在左侧。