Solved

Combobox

Posted on 1998-05-30
7
347 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 191
maro to copy and paste from one worksheet to another based on a condition 11 63
MS Date Picker 64 bit 32 bit issue 12 63
Hide vba in gp 7 113
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

680 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