在CheckBox检查中更改行颜色

时间:2017-10-25 14:30:13

标签: vb.net checkbox datagridview

我有一个包含多个列的DataGridView,第一个是CheckBox列。我想要的是,当用户检查任何行的复选框时,行颜色将改变(任何颜色)。这是我到目前为止所尝试的:

Private Sub dataGridView1_CellValueChanged(sender As Object, e As 
    DataGridViewCellEventArgs)
    If DataGridView1.Columns(e.ColumnIndex).Name = "ColCheck" Then
        If DataGridView1.Rows(e.RowIndex).Cells("ColCheck").Value = True Then

            Dim isChecked As Boolean = DirectCast(dataGridView1(e.ColumnIndex, e.RowIndex).FormattedValue, [Boolean])
            If isChecked Then
                DataGridView1.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.LightGreen
            End If
        End If
    End If
End Sub

但它不起作用。任何解决方案?

0 个答案:

没有答案