mercredi 25 octobre 2017

change row color on checkbox check VB.NET

i have a dgvw with multiple columns and the first one is a checkbox column.What i want is, when a user checks any row's checkbox the row color will change(any color)...This is what i've tried so far :

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

But it doesn't work...any solution ?




Aucun commentaire:

Enregistrer un commentaire