views:

29

answers:

2

How can I handle aCheckedChanged event for a cell in a DataGridViewCheckBoxColumn?

Note: If applicable, I prefer VB.NET answers over C#, but I'll accept either.

+2  A: 

Try attaching a handler to the DataGridView.CellValueChanged event; it's fired when any cell in the GridView changes, and will provide your handler information about the particular cell that changed. If the cell is a DataGridViewCheckBoxCell, the only data change that could happen would be that the checkbox was set or cleared. You can delegate that information to a more specific handler method, either through direct invocation or by raising your own event that other handlers listen for.

KeithS
+2  A: 

You'll have to handle the CellValueChanged event.

This code could be of help to you.

Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
    Dim checkColumnIndex = 1 'replace this with the appropriate method to get the checkbox column's index'
    If e.ColumnIndex = checkColumnIndex Then
        'do something
        Debug.Print("Cell " & Chr(e.ColumnIndex + 65) & e.RowIndex & " has changed.")
    End If
End Sub
Alex Essilfie
Just for your information, the `Debug.Print` statement I added outputs to the debug console which cell has changed in the format `Cell L## has changed`. It's pretty rudimentary anyway.
Alex Essilfie