-
Nov 17th, 2013, 06:40 PM
#1
Thread Starter
PowerPoster
Is there a way to copy items from one listbox to the other?
Hi there everyone! I am working on a small prog where I need to be able to just copy the items from one listbox to another. Would anyone know of a simple way to copy whatever is in list1 into list2?
Thank you so much!!
-
Nov 17th, 2013, 06:44 PM
#2
Re: Is there a way to copy items from one listbox to the other?
I think this question has come up before! You might find an example floating around this forum or the VB6.0 and Earlier code bank.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 17th, 2013, 09:27 PM
#3
Re: Is there a way to copy items from one listbox to the other?
One very simple way is to loop through list1 and add items to list2
Code:
dim i as integer
list2.clear
For i=0 to List1.listcount-1
list2.additem list1.list(i)
Next
-
Nov 19th, 2013, 07:10 AM
#4
Re: Is there a way to copy items from one listbox to the other?
Or, if you just want to move/copy some of the items from one listbox to another listbox (but not all of the items)
Code:
Private Sub Command1_Click()
Dim i As Long
For i = List2.ListCount - 1 To 0 Step -1 ' counts list entries
If List2.Selected(i) = True Then ' if selected then
List1.AddItem List2.List(i) ' add to other list
List2.RemoveItem i ' optional - use only if you wish to remove the item from the source listbox
End If
Next
End Sub
-
Nov 19th, 2013, 09:14 AM
#5
Re: Is there a way to copy items from one listbox to the other?
uhmmmm?
Code:
Listbox2.List=Listbox1.List
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Nov 19th, 2013, 09:18 AM
#6
Re: Is there a way to copy items from one listbox to the other?
Originally Posted by Zvoni
uhmmmm?
Code:
Listbox2.List=Listbox1.List
uhmmmm?
That does not work in VB6, results in argument not optional error
-
Nov 19th, 2013, 09:50 AM
#7
Re: Is there a way to copy items from one listbox to the other?
Damn! it works in VBA.... *grml*
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Nov 19th, 2013, 09:53 AM
#8
Re: Is there a way to copy items from one listbox to the other?
OK, since i confused everyone (again) by stepping into the VB/VBA-trap and its differences, here is a solution i found to copy the complete contents of one listbox to another listbox:
http://www.devx.com/vb2themax/Tip/19097
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|