PDA

View Full Version : Transfer ListBox1.List to ListBox2.List



Ann_BBO
08-08-2007, 08:50 PM
After Analysis the data, then i want to put all Listbox1.list into the ListBox2.list. Also, it will delete the list in listbox1 after analysis.
For delete the list in listbox1, i had success to do it. But i cannot transfer the listbox1.list into listbox2.list
' Try to put the List of ListBox1 to the ListBox2
With ListBox2
For x = 0 To ListBox1.ListCount - 1
.List = ListBox1.List(x)
Next x
End With

' Delete the filepath in the listbox1
With ListBox1
For k = .ListCount - 1 To 0 Step -1
.RemoveItem k
Next k
End With

The original filelist in listbox1.
' Display full path and name of the files
For i = LBound(sFiles) To UBound(sFiles)
sFileShort = Right(sFiles(i), Len(sFiles(i)))
With Me.ListBox1
.MultiSelect = 2
.AddItem sFileShort
.List(.ListCount - 1, 1) = sFiles(i)
End With
Next

Thanks

Ann_BBO
08-08-2007, 09:20 PM
Solve it:
' Transfer the List of ListBox1 to the ListBox2
For i = ListBox1.ListCount - 1 To 0 Step -1
ListBox2.AddItem ListBox1.List(i)
Next i

Thanks

Bob Phillips
08-09-2007, 01:21 AM
Don't forget to clear ListBox 2 at the start of this routine, in case it is a repeat action.

rory
08-09-2007, 04:39 AM
You can just use:
Listbox2.List = Listbox1.List

Ann_BBO
08-09-2007, 05:18 AM
Thanks for xld and rory