Click here to Skip to main content
12,694,121 members (34,191 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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 16-Mar-11 0:41am
Updated 16-Mar-11 1:55am
Prerak Patel141.9K
v3

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Use CellContentClick

[Edit]
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
  Permalink  
v2
Comments
Amit Kumar Tiwari 16-Mar-11 6:18am
   
Perfect answer, +5
Prerak Patel 16-Mar-11 6:20am
   
Thanks
kfsehgal 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.
kfsehgal 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.
Prerak Patel 16-Mar-11 23:38pm
   
I have updated the answer, you can check that now.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 16 Mar 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100