我正在使用这段代码:
// Cell value change event.
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if ((bool)dataGridView1.CurrentCell.Value == true) MessageBox.Show("true");
if ((bool)dataGridView1.CurrentCell.Value == false) MessageBox.Show("false");
MessageBox.Show(dataGridView1.CurrentCell.Value.ToString());
}
它适用于所有列,除了带有复选框的一列(DataGridViewCheckBoxColumn
)
我需要知道复选框列中的值(真或假)。
为此我需要做什么?
与...一起工作DataGridViewCheckBoxColumn
有时可能有点棘手,因为有一些规则专门适用于Cells
此列类型。此代码应该可以解决您遇到的问题。
The CurrentCellDirtyStateChanged
单击单元格时事件立即提交更改。您手动升高CellValueChanged
调用时发生的事件CommitEdit
method.
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.CurrentCell == null) return;
if ((bool)dataGridView1.CurrentCell.Value == true) MessageBox.Show("true");
if ((bool)dataGridView1.CurrentCell.Value == false) MessageBox.Show("false");
MessageBox.Show(dataGridView1.CurrentCell.Value.ToString());
}
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
Visit here有关与合作的更多信息DataGridViewCheckBoxCell
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)