Mason Wheeler
Mason Wheeler

Reputation: 84650

Combo box that can open quickly with lots of items

I've got a custom combo box descended from DevExpress's TdxfCustomComboBox. It works really well in most cases... and then I got a report from a client that when they try to open it it takes 3 seconds for the popup to appear. After a bit of investigation, I found out that that's because their database has about 12000 items that it's trying to populate, and it recreates the popup window and populates it each time.

This means that StdCtrls.TListBoxStrings.Add, which contains this line, gets called 12000+ times, once for each string.

SendMessage(ListBox.Handle, LB_ADDSTRING, 0, Longint(PChar(S)));

Processing this line requires several trips through multiple layers of message handlers and really bogs things down. I find this kind of silly since only about a dozen or so items are actually displayed in the popup window at once anyway. Does anyone know of a combo box control that doesn't require this sort of pre-loading and can scale?

EDIT: Unfortunately, making it not load 12,000 items is not an option here. The number of items in the combo box is based on the number of items in the database, and they all have to be available. Neither is making it into something other than a combo box. Not enough screen real estate for that.

Upvotes: 3

Views: 2531

Answers (7)

Wim ten Brink
Wim ten Brink

Reputation: 26682

This is just a foolish design! A better option is to add a button which the user can click on. When he clicks on it, a new form opens with a connection to the options table and it will display all the options in the way you prefer. The user then has to select one, could use pageUp/PageDown and all kinds of filters because -of course- you'd be using a DBGrid to display the options and then the user clicks the "Select" button which will return the selected option back.
A new form would provide all the space you would need!
From a design viewpoint, anyone considering a dropdown list with 12.000 options will be considered a fool by the users of this software! It would definitely make it very unpopular, no matter how fast you make it! Why, you say? Because users can't find what they need in a list that big without additional search options!

Upvotes: 0

markus_ja
markus_ja

Reputation: 2951

Maybe you can use a LookupComboBox (also from DevExpress). Here you can load the data into a single DataSet where the Comboboxs are refering to it.

Upvotes: 1

Chris Thornton
Chris Thornton

Reputation: 15817

ComboBoxes and ListViews experience performance degradation on an exponential curve, becoming really bad with thousands of items. Use Virtual lists whenever possible, if you have more than a few thousand.

Upvotes: 1

Larry Lustig
Larry Lustig

Reputation: 50998

Another possibility: can you create the combo box at start-up and keep it around, reparenting it when you need it on this form?

Failing that, could you load the strings into another string list and .Assign to the combo box as necessary? (I'm not familiar with TListBoxStrings.)

Upvotes: 2

Larry Lustig
Larry Lustig

Reputation: 50998

Honestly, three seconds sounds pretty good for loading 12000 records into a control like that.

Does the drop-down have to descend from TdxfCustomComboBox? I think you'd be better off rolling your own combo-box-like control here that would page through an associated dataset as required rather than pre-loading all the strings. Ideally you could build filtering into it too.

Upvotes: 0

user497849
user497849

Reputation:

the best solution that I can think of is using a TButtonEdit and when you click on the button a TVirtualStringTree(which is lightning fast) will popup containing the items, whenever the user clicks on a item the popup will close and the selected item will be displayed in the TButtonEdit's text property -- this can be achieved in a matter of minutes(5-10)

Upvotes: 7

Tim Jarvis
Tim Jarvis

Reputation: 18825

Some options.

1./ Do you really have to populate with 12,000 items? can you use some filtering scheme and only return a subset of that data?

2./ Do you have to use a Combo box? do you have the screen real estate to use a virtual list view instead? (handle the storage and paging yourself)

3./ Create your own Virtual combo box...model the virtualization techniques on the virtual list view.

4./ Cheat...rather than a combo box, use a edit box with a "browse" button that opens a list that you can fill dynamically.

As far as I know there is no mode that lets you do this already with the dev express (or native) combo boxes.

Upvotes: 1

Related Questions