Click to See Complete Forum and Search --> : Using Listboxes to move names
I have been trying to move a list of names 1 at a time or the whole names at a go from a "listbox1" to a "Listbox2" both on the same form. This should happen whenever I click on 2 command buttons at different times. The first and second buttons have "Add" and "Add All" written on them. Any help would be much appreciated.
Thanks
Albert
Joacim Andersson
Dec 15th, 1999, 01:59 PM
Try this for moving one item (the one that is selected):
Private Sub cmdAdd_Click()
List2.Add List1.List(List1.ListIndex)
List1.Remove List1.ListIndex
End Sub
And to move them all:
Private Sub cmdAddAll()
Dim i As Integer
For i = List1.ListCount - 1 To 0 Step -1
List2.Add List1.List(i), 0
List1.Remove i
Next
End Sub
Good luck!
------------------
Joacim Andersson
joacim@programmer.net
joacim@yellowblazer.com
www.YellowBlazer.com (http://www.YellowBlazer.com)
cjwares
Dec 15th, 1999, 02:05 PM
This should work:
For the add one button:
Private Sub Command1_Click()
List2.AddItem List1
End Sub
For the add all button:
Private Sub Command2_Click()
For n = 1 To List1.ListCount
List1.ListIndex = n - 1
List2.AddItem List1
Next n
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.