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
Solved

Combobox

Posted on 1998-05-30
7
346 Views
Last Modified: 2010-05-03
I have a combobox/listbox in a form and I want to fill the list with > 1000 items when the form loads. However, this process is very slow, it takes a few seconds before the form finish loading. Is there any way to improve this?
Loading all form at startup is not a good option for me because sometimes I need to create new instances of the forms.
0
Comment
Question by:leeal
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:JayMerritt
ID: 1462108
What's taking the longest time, the database lookup or the AddItems?

Is the data static or dynamic?

Do you use the same control and values on each form?


0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 50 total points
ID: 1462109
Use SendMessage with WM_INITSTORAGE to init the storage buffer, and LockWindowUpdate to disable the refresh while you're adding the items
0
 
LVL 1

Author Comment

by:leeal
ID: 1462110
MikeP, can you give me more detail information about the WM_INITSTORAGE message?
I can't find it in API Viewer. Thanks.

JayMerritt, AddItems is taking the longest time. Data is dynamic. Each form use different control.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 8

Expert Comment

by:MikeP090797
ID: 1462111
Sorry, it's CB_INITSTORAGE (&H0161)
0
 
LVL 1

Author Comment

by:leeal
ID: 1462112
MikeP, I just added the CB_INITSTORAGE message and LockWindowUpdate but it only improve the speed very little. So I tried to use the CB_ADDSTRING and CB_SETITEMDATA messages to add items instead of using Combo1.additem and Combo1.itemdata and it's twice as fast, but still I can feel the lag when the form loads. Is there anything else I could do to make it even faster? Here's a part of my code:

    Window_LockUpdate Me
    Combo1.Clear
'-- Combo_InitStorage calls the CB_INITSTORAGE message --
    Combo_InitStorage Combo1, Rst.RecordCount, Rst("Field2").Size + Rst("Field1").Size
    cbohWnd = Combo1.hWnd
    Do Until Rst.EOF
        NewIndex = SendMessageByString(cbohWnd, CB_ADDSTRING, 0&, Rst("Field2"))
        Call SendMessageByString(cbohWnd, CB_SETITEMDATA, NewIndex, Rst("Field1"))
        'With Combo1
            '.AddItem Rst("Field2")
            '.ItemData(.NewIndex) = Rst("Field1")
        'End With
        Rst.MoveNext
    Loop
    Rst.Close
    Window_UnLockUpdate

0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1462113
If you put that in your form_load event, make the first line Me.Show to show the form before you add the items, so the user will know your program isn't dead. Besides that, I don't think there is anything you can do.
0
 
LVL 1

Author Comment

by:leeal
ID: 1462114
Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

860 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