VB.NET DataGridView on select whole row

datagridviewvb.netvisual studio 2010

I have a question for the DataGridView in vb.net (making a form).

I have a button that is disabled. This button should only be enabled when a row in this list is marked/selected/highlighted. How can i write this? A doubleclick on the DataGridView gives me

Private Sub My_Grid_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles My_Grid.CellContentClick

End Sub

This only works on some of the cells and does not do any thing if i click on the * to the left where i select and highlight this row.

How do i do this?

Best Answer

SelectedIndexChange event can be selected as shown

You need to change the Event name to Handles My_Grid.SelectedIndexChanged

So the full Sub would be something like

Private Sub My_Grid_CellContentClick(ByVal sender As Object, ByVal e As EventArgs) Handles My_Grid.SelectedIndexChanged
     'Your code that handles this event here.
    End Sub
Related Topic