Solved

Duplicating a LISTBOX with Content Existing Already

Posted on 1999-01-09
5
223 Views
Last Modified: 2010-05-03
Is it possible to duplicate a LISTBOX that has content already existing in it so that i can have a second listbox with the EXACT content that was held in the original listbox? So, for example i have:

List1.list(0)="Hello"
List1.list(1)="There"

List2 = list1

Now List2 should have ALL of the same properties, including content as LIST1.

Thanks

0
Comment
Question by:aniston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1455098
You could try something like this:

Private Sub CopyListBox(Source As ListBox, Target As ListBox)
   
    Dim mintCurrentListItem As Integer
    Target.Clear
    For mintCurrentListItem = 0 To Source.ListCount - 1
        With Target
            .AddItem Source.List(mintCurrentListItem)
            .ItemData(.NewIndex) = Source.ItemData(mintCurrentListItem)
        End With
    Next
End Sub

Private Sub cmdCopyContents_Click()
    CopyListBox List1, List2
End Sub
0
 

Author Comment

by:aniston
ID: 1455099
Oh...i am sorry. I should have elaborated more. I already knew i could do the method you just proposed mcix ... Sorry for not mentioning this in my original post. (Edited by Computer101).. The reason i am asking to duplicate a listbox in one single copy is because i notice when you have some 6000 items inside a listbox and you attempt to duplicate these items into another listbox that process takes VERY LONG. I was hoping there was an a better way to copy such a large amount of data into the other at a quicker pace.. Can anyone else provide a solution to this UNIQUE problem.

0
 
LVL 15

Expert Comment

by:ameba
ID: 1455100
It is faster if you cache Source.ListCount - 1 before loop:
    Dim slc As Integer
    slc = Source.ListCount - 1
    For mintCurrentListItem = 0 To slc

and set Visible property of Target listbox
' before Target.Clear
   Target.Visible = False
' after loop
   Target.Visible = True

Warning:
If your Target listbox has Sorted=True, code will execute slow.

And putting 'With Target' outside loop (as mcix did) is very important.
0
 
LVL 4

Expert Comment

by:mcix
ID: 1455101
Good Points!
0
 

Accepted Solution

by:
edunc earned 20 total points
ID: 1455102
woah!  those other explinations were long!  You'll probably like this one a lot better!


  'this is so there is something in list1.  you would probably replace this with something else in your program.
  List1.AddItem "hello"
  List1.AddItem "there"

  'this will copy the contents of list1 to list2
  For i = 0 To List1.ListCount - 1
    List2.List(i) = List1.List(i)
  Next i

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question