How to check a Datagridviewcheckboxcolumn column in VB.NET

Asked

Viewed 53 times

-2

I saw that there is a lot of material on how to verify if the check is marked or not, but I am not able to mark the box of the object inside the Datagrid. by clicking on the Datagridviewcheckboxcolumn it does not mark. Someone can help ?

  • Place snippets of your code to know what we can help you with

  • @Eduardooliveira I created the datagrid and want to add a Datagridviewcheckboxcolumn column to mark the entire row. I did almost everything via Design msm, including adding the columns. The problem is that when running the program you cannot check. You know what can be?

  • Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English.

1 answer

1


The idea is you create a method to check the change of state.

      Private Sub dgv_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv.CellContentClick
            // vê se a culuna clicada é a que tem o checkbox
          If dgv.CurrentCell.ColumnIndex = 0 Then
            // vê se a linha está marcada true
             If dgv.Item(0, dgv.CurrentRow.Index).Value() Then
                dgv.Item(0, dgv.CurrentRow.Index).Value() = False
             Else
                dgv.Item(0, dgv.CurrentRow.Index).Value() = True
             End If
          End If
       End Sub

You might be able to take that kind of check.

  • so I need a method just to check the component? or if I click it it should check/uncheck and then do the check?

  • The idea is to use Cellcontentclick and catch the click event on your grid. Taking this event, you should check if the click was in the column where your checkbox is. If your checkbox is marked you then uncheck and the opposite applies.

  • I could understand and your example was very useful. ;)

Browser other questions tagged

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