Home » Controls » How to Drag/Move items from one List Box to another List Box
How to Drag/Move items from one List Box to another List Box
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 'Controls - How to Drag/Move items from one List Box to another List Box Option Explicit 'Add two List Boxes and a Text Box 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 'The following statement will remove the moved item from list 1 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 'The following statement will remove the moved item from list 2 List2.RemoveItem (List2.ListIndex) End Sub |
Enjoy this article?
Filed under: Controls
Leave a comment