DataGridView check box column event to see when clicked

Hi

In VB.net 2010 I need to run code when a check box column is checked.
How do I achieve this?
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
nepaluzConnect With a Mentor Commented:
first and foremost, you have to handle the CurrentCellDirtyStateChanged event to ensure that when you click the value is commited. Below is an example of handling that event for my DataGridView1
    Sub dataGridView1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
        If DataGridView1.IsCurrentCellDirty Then
            DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
        End If
    End Sub

Open in new window

This will ensure that the cell value changed event will fire straight away and not wait for you to click another cell.
Then youcan hadle the cellvaluechanged event
    Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
       'here with your code
    End Sub

Open in new window

0
 
jppintoCommented:
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
       
Dim s As DataGridViewCell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
       'your code here
End Sub
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much. Things finally worked with your code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.