开发者

Handle .NET DataGridViewCheckBox Changed Event

开发者 https://www.devze.com 2023-01-15 06:13 出处:网络
How can I handle aCheckedChanged event for a cell in开发者_JAVA技巧 a DataGridViewCheckBoxColumn?

How can I handle aCheckedChanged event for a cell in开发者_JAVA技巧 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
0

精彩评论

暂无评论...
验证码 换一张
取 消