• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

DataGridView check box column event to see when clicked


In VB.net 2010 I need to run code when a check box column is checked.
How do I achieve this?
Murray Brown
Murray Brown
  • 2
1 Solution
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
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
        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

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much. Things finally worked with your code.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now