DataGridView check box column event to see when clicked

Posted on 2011-10-17
Last Modified: 2012-06-21

In 2010 I need to run code when a check box column is checked.
How do I achieve this?
Question by:murbro
    LVL 33

    Expert Comment

    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
    LVL 33

    Expert Comment

    LVL 17

    Accepted Solution

    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


    Author Closing Comment

    Thanks very much. Things finally worked with your code.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now