Solved

Combobox

Posted on 1998-05-30
7
344 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

806 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