有没有办法阻止用户选择特定dgvRow中的单元格 Row是ReadOnly,但仍然可以选择。
答案 0 :(得分:2)
您可以添加自定义委托,以便在更改选择时取消选择相关单元格。
DataGridView1.SelectionChanged += new EventHandler(DataGridView1_SelectionChanged);
private void DataGridView1_SelectionChanged(object sender, EventArgs e){
List<DataGridViewCell> toBeRemoved = new List<DataGridViewCell>();
foreach(DataGridViewCell selectedCell in DataGridView1.SelectedCells){
if (isCellUnSelectable(selectedCell))
toBeRemoved.Add(selectedCell);
}
foreach(DataGridViewCell cell in toBeRemoved){
cell.Selected = false;
}
}