16,554
社区成员
发帖
与我相关
我的任务
分享
'Check box column index
Private CheckColIndex As Integer = 0
Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
'Check the column index and if the check box is checked.
If e.ColumnIndex = CheckColIndex Then
Dim isChecked As Boolean = CType(Me.DataGridView1(e.ColumnIndex, e.RowIndex).Value, Boolean)
If isChecked Then
'If check box is checked, uncheck all the rows, the current row would be checked later.
For Each row As DataGridViewRow In Me.DataGridView1.Rows
row.Cells(e.ColumnIndex).Value = False
Next
End If
End If
End Sub