0
我試圖通過掛接到DataGrid的SelectedCellsChanged
事件來讓用戶避免在多列上進行單元選擇。WPF DataGrid:禁用多列選擇
不過,出於某種原因,我的代碼表現得有點奇怪。
這裏是我的代碼:
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);
}
}
誰能告訴我什麼,我在這裏失蹤?