-
May 21st, 2016, 04:53 PM
#1
Thread Starter
Addicted Member
Drag/Drop From 1 List To Another...
I'd like to drag a single item from one ListBox to another. I don't want any items removed from any ListBox. I don't want the entire box shown being dragged... just the item I've selected. For some reason, all of the examples I've found do different things and never seem to show something as simple as this should be. All help is appreciated.
-
May 21st, 2016, 05:30 PM
#2
Re: Drag/Drop From 1 List To Another...
Code:
Dim List1_ItemDraged As Integer
Dim List2_ItemDraged As Integer
Private Sub Form_Load()
List1.AddItem "List1 Item 0"
List1.AddItem "List1 Item 1"
List1.AddItem "List1 Item 2"
List1.AddItem "List1 Item 3"
List2.AddItem "List2 Item 0"
List2.AddItem "List2 Item 1"
List2.AddItem "List2 Item 2"
List2.AddItem "List2 Item 3"
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If List1.ListCount > 0 Then
For q = 0 To List1.ListCount ' - 1
On Error Resume Next
If List1.Selected(q) = True Then
If Err Then Exit Sub
Exit For
End If
Next q
Dim DY ' Declare variable.
Dim DX
DY = TextHeight("A") ' Get height of one line.
DX = TextWidth(List1.Text)
If Y > List1.ListCount * DY Then
List1.Selected(q) = False
Exit Sub
End If
'
' Note: The +75 and -75 is only to keep the width of the label
' within the inside width of the list box
'
'Label1.Move List1.Left + 75, _
' List1.Top + Y - DY / 2, _
' List1.Width - 75, _
' DY
Label1.Move List1.Left + 75, _
List1.Top + Y - DY / 2, _
DX, _
DY
List1_ItemDraged = List1.ListIndex
Label1.Caption = List1.Text
Label1.Drag ' Drag label1 outline.
End If
End Sub
Private Sub List2_DragDrop(Source As Control, X As Single, Y As Single)
If Source = Label1 Then
List2.AddItem List1.Text
End If
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
May 21st, 2016, 06:29 PM
#3
Thread Starter
Addicted Member
Re: Drag/Drop From 1 List To Another...
I suppose that's one way. Not really looking to add controls to make it happen, though. Should be just a simple drag/drop example.
-
May 21st, 2016, 08:27 PM
#4
Re: Drag/Drop From 1 List To Another...
Code:
Private Sub Form_Load()
List1.AddItem "A"
List1.AddItem "B"
List1.AddItem "C"
List1.ListIndex = 0
List1.DragIcon = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Dragdrop\drag2pg.ico")
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.Drag vbBeginDrag
End Sub
Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.Drag vbEndDrag
End Sub
Private Sub List2_DragDrop(Source As Control, X As Single, Y As Single)
If Source Is List1 Then
List2.AddItem Source.Text
End If
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|