Solved

Combobox

Posted on 1998-05-30
7
340 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 8

Expert Comment

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

Author Comment

by:leeal
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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 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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now