我是一个新手,正在做我的第一个C#项目(也没有在Haskell和C方面的最少经验),以寻求有关如何在程序中实现小功能的指南。
我有一个DataGridView表(具有3列复选框以及其他内容)供用户填充。连续时,第二个复选框处于选中状态,第一个被选中的复选框必须未选中。我可以执行此操作,但问题是,在我选择表中的其他内容后,第一个选中的对象才被取消选中。
这是与CellValueChanged事件有关的代码(注释中的内容是我试图帮助我的内容)
if (e.ColumnIndex == 0 || e.ColumnIndex == 1 || tabela_NormasDataGridView.Rows.Count == 0)
{
return;
}
var isChecked = (bool)tabela_NormasDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (isChecked)
{
for (int i = 2; i < 5; i++)
{
//Console.WriteLine("og " + e.ColumnIndex);
DataGridViewCell cell = tabela_NormasDataGridView.Rows[e.RowIndex].Cells[i];
//Console.WriteLine("segunda " + cell.ColumnIndex);
if (cell.ColumnIndex != e.ColumnIndex)
{
cell.Value = false;
//this.Refresh();
}
}
}
感谢您的时间!
尝试提交更改以强制刷新:
void tabela_NormasDataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e) {
tabela_NormasDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
确保将事件连接起来。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句