Make your own free website on Tripod.com

Drag/Move Items From One List Box To Another

'Add 2  List Boxes and 1 Text Box to your form.
'The drag Icon will be at the size of the Text Box.
'Insert the following code to your form:

Private Sub Form_Load()
Text1.Visible = False
List1.AddItem "Apple"
List1.AddItem "Orange"
List1.AddItem "Grape"
List2.AddItem "Banana"
List2.AddItem "Lemon"
End Sub

Private Sub List1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If List1.ListCount = 0 Then Exit Sub
Text1.Text = List1.Text
Text1.Top = Y + List1.Top
Text1.Left = X + List1.Left
Text1.Drag
End Sub

Private Sub List2_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If List2.ListCount = 0 Then Exit Sub
Text1.Text = List2.Text
Text1.Top = Y + List2.Top
Text1.Left = X + List2.Left
Text1.Drag
End Sub
Private Sub list2_DragDrop(Source As Control, X As Single, Y As _
Single)
For i = 0 To List2.ListCount - 1
If List2.List(i) = Text1 Then Exit Sub
Next
List2.AddItem Text1.Text
'If you want that the item will be also deleted from the dragged List Box, uncomment
'The line below

'List1.RemoveItem (List1.ListIndex)
End Sub
Private Sub list1_DragDrop(Source As Control, X As Single, Y As _
Single)
For i = 0 To List1.ListCount - 1
If List1.List(i) = Text1 Then Exit Sub
Next
List1.AddItem Text1.Text
'If you want that the item will be also deleted from the dragged List Box, uncomment
'The line below

'List2.RemoveItem (List2.ListIndex)
End Sub

Go Back