Hi,
I have a dgv displaying records from an SQL database. On load, the dgv is filled, the dgv selection cleared and the 'action' buttons set to enabled=false. When the user selects a row (cellclick action) the 'action' buttons are enabled. When the action button is clicked the dgv is reloaded, the selection cleared and the action buttons are disabled. This all works fine.
I have been asked to allow 'multiselect' for certain actions. I have allowed multiselect on the dgv and ran a test.
The user selects multiple rows with either control or shift, multiselect works BUT

If the user clicks down on one row, drags down over several rows and then releases the mouse the rows are highlighted correctly in the dgv, but the 'cellclick' trigger does not fire so the 'action' buttons do not enable. If I use the 'dgv.selectionchanged' then this action triggers repeatedly as the dgv loads initially and the code crashes.

Is there another trigger I should check for, or is there a better solution.
Many thanks

Yes ! dgv.selectionchanged is the correct event you selected.
You did right, but you didn't check the conditions for dgv.SelectedRows.Count. The codes should be

Private Sub DGV_SelectionChanged(sender As Object, e As System.EventArgs) Handles DGV.SelectionChanged
        If DGV.SelectedRows.Count > 0 Then
            Action_Button.Enabled = True
        Else
            Action_Button.Enabled = False
        End If
End Sub

Hope it can help u.

sorted thank you. The other thing I was doing wrong, was to have one sub '... handles dgv.cellclick, dgv.selectionchanged' rather than have two separate subs - one to handle the cellclick and the other to handle the selectionchanged.

Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.