代码之家  ›  专栏  ›  技术社区  ›  Steven

处理.NET DataGridViewCheckBox更改事件

  •  1
  • Steven  · 技术社区  · 15 年前

    CheckedChanged DataGridViewCheckBoxColumn ?

    如果适用,我更喜欢VB.NET版答案超过C#,但我接受任何一个。

    2 回复  |  直到 15 年前
        1
  •  2
  •   KeithS    15 年前

    尝试将处理程序附加到DataGridView.CellValue已更改事件;它在GridView中的任何单元格更改时激发,并将提供有关更改的特定单元格的处理程序信息。如果单元格是DataGridViewCheckBoxCell,则唯一可能发生的数据更改是复选框已设置或清除。您可以通过直接调用或引发其他处理程序侦听的您自己的事件,将该信息委托给更具体的处理程序方法。

        2
  •  2
  •   Alex Essilfie    15 年前

    你得处理这个问题 CellValueChanged 事件。

    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
    
    推荐文章