Results 1 to 9 of 9

Thread: [RESOLVED] Listbox Multiselect, Double Click, And Drag&Drop

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2022
    Posts
    23

    Resolved [RESOLVED] Listbox Multiselect, Double Click, And Drag&Drop

    Hello!
    I have an application that has two list box controls, and I've tried to enable the drag and drop feature between the two lists, but I have some problems, I want to combine the drag and drop with some other features:
    1-The list box has the multi extended selection mode enabled.
    2-The double-click on an item opens a form with the selected item properties.
    3-The right click opens a context menu.

    I've tried to use a custom control that I found on this forum, but I still have bugs with the double click, sometimes "enables" the drag and drop instead of opening the properties form. Here is the custom control I'm using:
    https://www.vbforums.com/showthread....=1#post3079759

    Here are the methods I'm using:

    Code:
    Private Sub ListBox_DataBaseSFX_MouseMove(sender As Object, e As MouseEventArgs) Handles ListBox_DataBaseSFX.MouseMove
    	If sender IsNot Nothing AndAlso e.Button = MouseButtons.Left AndAlso e.Clicks = 1 Then
    		ListBox_DataBaseSFX.DoDragDrop(ListBox_DataBaseSFX.SelectedItems, DragDropEffects.Move)
    	End If
    End Sub
    
    Private Sub ListBox_DataBaseSFX_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles ListBox_DataBaseSFX.MouseDoubleClick
    	'Ensure that we have selected an item
    	Dim itemIndex = ListBox_DataBaseSFX.IndexFromPoint(e.Location)
    	If itemIndex <> ListBox.NoMatches Then
    		'Get item and file path
    		Dim selectedSFX As String = ListBox_DataBaseSFX.Items(itemIndex)
    		'Open editor
    		Dim sfxEditor As New SfxEditor(selectedSFX)
    		sfxEditor.ShowDialog()
    	End If
    End Sub
    
    Private Sub ListBox_DataBaseSFX_DragOver(sender As Object, e As DragEventArgs) Handles ListBox_DataBaseSFX.DragOver
    	e.Effect = DragDropEffects.Copy
    End Sub
    
    Private Sub ListBox_DataBaseSFX_DragDrop(sender As Object, e As DragEventArgs) Handles ListBox_DataBaseSFX.DragDrop
    	If e.Effect = DragDropEffects.Copy AndAlso ListBox_DataBases.SelectedItems.Count > 0 Then
    		If e.Data.GetDataPresent(GetType(ListBox.SelectedObjectCollection)) Then
    			Dim itemsData As ListBox.SelectedObjectCollection = e.Data.GetData(GetType(ListBox.SelectedObjectCollection))
    			For Each data As String In itemsData
    				ListBox_DataBaseSFX.Items.Add(data)
    			Next
    		End If
    	End If
    End Sub
    EDIT:
    This custom control, gives me the option to select rows by clicking one row and dragging it, as we can do in Excel, for example. The idea is to combine this with the drag and drop and also allowing the double click.
    Last edited by jms2505; Jan 29th, 2022 at 04:54 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width