none
datagridview multiselect leftmouse buttom down RRS feed

  • Question

  • I have a Datagridview with 

    DGV.SelectionMode = DataGridViewSelectionMode.FullRowSelect

    DGV.MultiSelect = True

    I would like to avoid to mutliselect rows using the left mouse button pressed for several rows, since the multiselct should be performed just with the shift key and left mouse click

    Is it possible to disable this dgv function

    Wednesday, February 28, 2018 7:03 PM

Answers

  • Hi,

    In advance, sorry if I misunderstand what you want to achieve....

    It is possible.

      (1) handle CellMouseClick on DGV
      (2) count the number of selected rows
      (3) if (count > 1), then make (MultiSelect=False)
      (4) finally, make current row selected

    ' --- CellMouseClick (1)
    Private Sub DGV_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick
    	If (e.Button = MouseButtons.Left) Then
    		Dim rowCnt As Integer = DGV.SelectedRows.Count   ' --(2)
    		If (rowCnt > 1) Then
    			DGV.MultiSelect = False   ' --(3)
    		Else
    			DGV.MultiSelect = True
    		End If
    		DGV.CurrentRow.Selected = True   ' --(4)
    	End If
    End Sub


    Regards,


    Ashidacchi

    • Edited by Ashidacchi Thursday, March 1, 2018 6:40 AM
    • Marked as answer by Claudio111 Friday, March 2, 2018 12:55 PM
    Thursday, March 1, 2018 6:34 AM