Listbox selectionmode = multiextended how to get rid of the selection of elements with the mouse

When setting up the list selection method in multiscreen, I observed three ways to select items:

  • mouse click while holding down the switch key
  • holding down the Ctrl key
  • mouse click when moving the mouse over an unselected item

1 and 2. this is exactly the behavior that I want, but I do not want 3. because later I want to reorder the elements by moving all the selected elements up and down with the mouse.

How to get rid of 3.?

I need a behavior similar to a playlist in Winamp. Reorder items by dragging and copying palette items

+3
source share
2

ListBox SelectionMode. .

, . Ctrl, Shift, .

.

+3

"" , , . , , . .

  • "KeyPreview" , "True".
  • SelectionMode ListBox "MultiSimple".

, Control Shift.

Public Class Form1
    Private bSelectMode As Boolean = False

    Private Sub Form1_KeyUpOrDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown, Me.KeyUp
        bSelectMode = e.Control OrElse e.Shift
    End Sub

    Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
        If bSelectMode AndAlso e.Button <> Windows.Forms.MouseButtons.None Then
            Dim selectedindex = ListBox1.IndexFromPoint(e.Location)

            If selectedindex <> -1 Then
                ListBox1.SelectedItems.Add(ListBox1.Items(selectedindex))
            End If
        End If
    End Sub
End Class
+1

Source: https://habr.com/ru/post/1756647/


All Articles