Datagridview and checkbox - strange behavior.

Asked

Viewed 62 times

0

I have a datagridview with checkboxes. I have this code:

Private Sub DataGridView2_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView2.CellMouseClick
    If e.ColumnIndex > 1 Then
        DataGridView2(e.ColumnIndex, e.RowIndex).Value = True
    End If

End Sub

But the checkbox is only "checked" when Focus exits it. That’s just "checked" when I click on another object in the project.

2 answers

0

This is because whenever you click on a cell, and it is in a column with an index greater than 1:

If e.ColumnIndex > 1 Then 
    DataGridView2(e.ColumnIndex, e.RowIndex).Value = True
End If

your code is making the cell with the value ckeckbox as true always.

  • I already did, but thanks anyway.

0

I already took care of it. I was using the "cellvaluechanged" action and this was not being called in due time either.

The problem is that in Vb when we use checkboxes and datagridviews, it only performs "check" when we do Focus to another object.

To solve this I just put a line of code where I make Focus to another object and ready, checkboxes already work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.