【发布时间】:2015-06-06 13:56:47
【问题描述】:
我使用 CurrentCellDirtyStateChanged 处理我的复选框单击事件。当我单击包含复选框的 cell 时,我想要做的是处理相同的事件,即当我单击单元格时,选中复选框并调用 DirtyStateChanged。使用下面的代码没有多大帮助,它甚至没有调用 CurrentCellDirtyStateChanged。我的想法已经用完了。
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if(dataGridView.Columns[e.ColumnIndex].ReadOnly != true)
{
//option 1
(dataGridView.CurrentRow.Cells[e.ColumnIndex] as DataGridViewCheckBoxCell).Value = true;
//option 2
DataGridViewCheckBoxCell cbc = (dataGridView.CurrentRow.Cells[e.ColumnIndex] as DataGridViewCheckBoxCell);
cbc.Value = true;
//option 3
dataGridView.CurrentCell.Value = true;
}
}
【问题讨论】:
-
这是 XAML 吗?这将是比 [cell] 和 [checked] 更好的问题标签
-
为什么这个问题会得到减分?
-
投反对票是因为 SO 有很多固执己见的白痴认为这是增加价值的最佳方式。
-
我同意,这些白痴应该给出一个更好的解决方案,或者,至少是一个合理的理由以及赞成/反对票,而不是有偏见。
标签: c# winforms checkbox datagridview checked