Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I have a datagridview with a checkbox column. I want to capture the value of checkbox immediately when user changes it by clicking. I tried several events (CellValueChanged, CellClicked,CurrentCellDirtyStateChanged etc.) but nothing worked.
My code is
If dgvIDsTBC.CurrentRow.Cells(2).Value = True Then
      MsgBox("True")
End If

Please advise what event to use for this.
Thanks
Furqan
Posted
Updated 16-Mar-11 0:55am
v3

1 solution

Use CellContentClick

[Edit]
VB
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
    MsgBox(DirectCast(sender, Forms.DataGridView).Rows(e.RowIndex).Cells(e.ColumnIndex).EditedFormattedValue)
  End Sub
 
Share this answer
 
v2
Comments
Wild-Programmer 16-Mar-11 6:18am    
Perfect answer, +5
Prerak Patel 16-Mar-11 6:20am    
Thanks
Furqan Sehgal 16-Mar-11 13:08pm    
CellContentClick does not work.
Prerak Patel 16-Mar-11 13:17pm    
That is not enough, show how you did it. It would definitely work.
Furqan Sehgal 16-Mar-11 13:26pm    
Actually the above given method works, but partially in the way I want.
I gave this code

MsgBox("Clicked")
MsgBox(DataGridView1.CurrentRow.Cells(2).Value)

While I want to capture the current value of checkbox, it True or False but in either cases, it show a blank box.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900