Home » Controls » How to move multiple items from one List Box to another List Box/Combo Box
How to move multiple items from one List Box to another List Box/Combo 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 | 'Controls - How to move multiple items from one List Box to another List Box/Combo Box Option Explicit 'Add two List Boxes and a Command Button to your form. 'Set List1 MultiSelect property to 1 - Simple. Private Sub Command1_Click() 'if List1 is empty - exit, to avoid error If List1.ListCount = 0 Then Exit Sub Dim CurItem As Integer CurItem = 0 Do 'if a item is selected If List1.Selected(CurItem) Then 'Add it to the second List Box. List2.AddItem List1.List(CurItem) 'Delete it from List1 List Box List1.RemoveItem (CurItem) Else CurItem = CurItem + 1 End If Loop Until CurItem = List1.ListCount End Sub Private Sub Form_Load() 'add few items to the List Box For I = 1 To 10 List1.AddItem "Item " & I Next End Sub |
Enjoy this article?
Filed under: Controls
Leave a comment