Results 1 to 5 of 5

Thread: Speed up ComboBox Loading

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    I am adding about at least 1500 to 3000 names to a combobox as show below.

    Is there a better way of getting the names in the box? As I add more and more names it takes progressively longer to add a name to the list.

    Any suggestions would be greatly appreciated.

    Code:
        For i = 1 to Ubound(username)
            Me.cboOldUserName.AddItem (TempUserName)
            Me.cboMACLsUserName.AddItem (TempUserName)
        Next i
    This space for rent...

  2. #2
    Addicted Member Michael Woolsey's Avatar
    Join Date
    Nov 2000
    Location
    Calgary, Alberta, Canada.
    Posts
    243
    Without using any APIs or anything like that, one way I have found to speed up things is to make the control invisible.

    This may help, I'm not certain in your case.

    Code:
    Me.cboOldUserName.Visible = False
    Me.cboMACLsUserName.Visible = False
    
    For i = 1 to Ubound(username)
      Me.cboOldUserName.AddItem (TempUserName)
      Me.cboMACLsUserName.AddItem (TempUserName)
    Next i
    
    Me.cboOldUserName.Visible = True
    Me.cboMACLsUserName.Visible = True
    I was doing a standard loop 1 to 3000 and added a string to the two combo boxes, it only took a second or two... perhaps there is something else that is slowing down your loop?

    Michael Woolsey
    Application/Web Developer

    Visual Basic 6.0 SP5
    Active Server Pages
    Oracle 9i
    - I'm going to live forever, or die trying!

  3. #3
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    This is a CHEAP fix . Set it's .visible propertie to false before you load it then when it's done make it visible again . I noticed this in an app awhile ago . Atleast it was true in my case but I was scrolling the box also . Try it , can't hurt .

    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  4. #4
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    I always use the LockWindowUpdate(xxxxx.hWnd) API to prevent the window from redrawing. After adding the items, simply use LockWindowUpdate(0&) to redraw it's contents.
    But also consider that when your list is sorted, this will ALSO take longer than an unsorted list.
    Otherwise, it's VERY VERY slow.
    A much more faster way to add items, is adding them to strings in memory. After loading you can display them using the Print method on a picturebox.

  5. #5

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    Thank you all for responses. I will give that a try.

    Originally posted by PRIVATE1
    This is a CHEAP fix.
    Curious, What's the expensive fix?
    This space for rent...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width