【发布时间】:2011-03-05 11:01:37
【问题描述】:
我正在使用 CellClick 事件并想更新网格上的另一个复选框。 示例: - 添加和删除列的两列。 用户单击添加,系统检查删除复选框是否也未选中。 如果选中删除 ------ 将删除设置为 false
换句话说,不能同时选中同一行的“添加”和“删除”复选框。
我正在使用...
private void customersDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
- 如何通过名称“添加”获取当前单元格的值。
- 如何通过名称“删除”获取另一个单元格的值。 上述过程是一个触发器。
如果我知道如何将单元格作为对象访问,我应该能够完成剩下的工作。
我一直在寻找使用 cmbBox = e.Control as ComboBox 的示例,但这不起作用:(
示例链接会有所帮助,谢谢。
从您建议的编辑中添加到答案 -Andomar
这行得通……
private void customersDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
//Set a var that determined whether or not the checkbox is selected
bool selected = (bool)this.customersDataGridView[e.ColumnIndex, e.RowIndex].Selected;
//Do the flip-flop here
const int add = 4;
const int delete = 5;
switch (e.ColumnIndex)
{
//If the checkbox in the Add column changed,
// flip the value of the corresponding Delete column
case add:
this.customersDataGridView[delete, e.RowIndex].Value = !selected;
break;
//If the checkbox in the Delete column changed,
// flop the value of the corresponding Add column
case delete:
this.customersDataGridView[add, e.RowIndex].Value = !selected;
break;
}
}
}
不需要 dataGridView1_CellMouseUp
【问题讨论】:
-
请注意,您可以 format lines as code 将它们缩进四个空格。编辑器工具栏中的“{}”按钮会为您执行此操作。您还可以通过在行前加上数字、句点和空格来格式化列表。编辑您的问题并尝试一下。单击编辑器工具栏中的橙色问号,了解有关使用 Markdown 进行格式化的更多信息和提示。
标签: c# winforms visual-studio-2008 datagridview