Solved

Duplicating a LISTBOX with Content Existing Already

Posted on 1999-01-09
5
230 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

623 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