DataGridView & Checkbox Column?

2019-08-25 12:17发布

Using vb.net and DataGridView in Winforms.

What event should I use to know when the checkbox has changed?

3条回答
甜甜的少女心
2楼-- · 2019-08-25 12:39

You need to set up an event handler to do work when a cell's contents have been changed. Then, based on the arguments passed, you can see if the checkbox was checked or unchecked, and do work accordingly.

    Private Sub myDataGrid_CellContentClick(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
    Handles myDataGrid.CellContentClick
         If myDataGrid.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = "True" Then
             'Checked condition'
         Else
             'Unchecked Condition'
         End If
    End Sub

Hope that helps!

查看更多
闹够了就滚
3楼-- · 2019-08-25 12:54

Is

DataGridViewCheckBoxCell.EditingCellValueChanged
what you want?

查看更多
你好瞎i
4楼-- · 2019-08-25 12:55

Did you mean how do you know when the DataGridView changes?

A DataGridView is not a checkbox at all.

Add an event handler to handle a CellValueChanged event.

Private Sub MySubName(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

End Sub

(replace MySubName with whatever you want, and DataGridView1 with the name of your DataGridView).

Fill in the body of the Sub to handle the event.

查看更多
登录 后发表回答