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.
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.
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.
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