1

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 etc.) but nothing worked.

This is my code:

If dgvIDsTBC.CurrentRow.Cells(2).Value = True Then
    MsgBox("True")
End If

Please help

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.