Datagridview checkbox column's value
I have a DataGridView with a checkbox column. I want to capture the value of the checkbox immediately when user changes it by clicking. I tried several events (CellValueChanged
, CellClicked
, CurrentCellDirtyStateChanged
e开发者_JAVA技巧tc.) but nothing worked.
This is my code:
If dgvIDsTBC.CurrentRow.Cells(2).Value = True Then
MsgBox("True")
End If
Please help
Hope this helps
void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
MessageBox.Show(dataGridView1[e.ColumnIndex, e.RowIndex].FormattedValue.ToString());
}
This i presume you would have done, now the catch is unless you move out of the cell the grid considers you are still editing ,So Add this part
void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == 3)
dataGridView1.EndEdit();
}
This should be fine for you, 3 is the checkbox column you intend it to work for
精彩评论