Combo box that can open quickly with lots of items - delphi

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.

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)

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.)

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.

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.

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.

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.

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!

Related

Can filters hide invisibly?

I'm very new to Tableau, just creating my third very simple Viz. By adding and deleting filters, I seem to have managed to create an invisible filter and I don't know how to get rid of it. I deleted the dashboard and all sheets but the filter persists somewhere.
In the data-source tab, when I describe the "mix" field it has 6 discrete values as it should. When I look at the table I can see 6 discrete values. But NOW when I create a brand new first sheet and don't do anything else but look at "describe" for "mix" in the list of fields, "mix" only has one value. If I drag it to the screen it shows up with that one value.
Any ideas where I might find this hidden filter?
Thank you.
Aha. I hadn't realized that making an extract of the source data (so that I could put the Viz up publicly) was silently filtered by the filters in place on a screen.
So, unknown to me, my source-data had become "pre-filtered" and of course nothing I could do at a screen level after that could remove that filtering.

Vaadin grid user column re-ordering and saving per user

How do people tend to let users re-order the grid columns and save that ordering for later?
The only way I can think of to do it, at least in Vaadin 7, is:
Listen for column re-ordering via addColumnReorderListener(…)
When re-order triggered, if user initiated, get columns from getColumns() and save to DB with any identifying information
When pull Grid back up, read grid ordering from DB and apply the same order with setColumnOrder(columns)
So is there a better way to do this? I just checked the Directory, could not find anything obvious to make this easier. Just looking for how others have addressed this user requirement. If Vaadin 14 already supports such actions a little easier, that would be good to know as well, as it might give me some ideas on how to get that ability short term before I can upgrade to Vaadin 14.
For a more customizable grid you can (in addition to what you've already done) add a button that opens a dialog that lists all possible columnnames, together with a checkbox.
Unchecking the checkbox removes the column, checking the checkbox adds the column.
Even more comfortable is when the dialog lists all available columns in a Grid with draggable rows and editable checkboxes, so that the user can show, hide and sort all columns in one place. After that you have to reorder all columns by calling grid.setColumnOrder.
Just so people know how I solved this issue, based on the comments:
When load data into Grid, first check database for columns of this Grid/user combination. If find such a column order, call setColumnOrder(userColumns).
Added 2 buttons to top, one to save column order, one to reset it.
"Save" button only enabled after moving at least one column.
"Reset" button only enabled if at least one column was moved. One column was moved either because of the DB, or because user JUST moved a column.
On save, save to DB. On reset, clear from DB, and reset Grid to original column order.
We chose not to save the column order each time they changed the order, directly in the addColumnReorderListener, because we realized sometimes users might move columns around temporarily, and one really want to save that column order for the future. That said, the saving inside the addColumnReorderListener worked well.
We don't currently need to save the column sizes, as suggested by #Simon Martinelli, but we are keeping it as an idea for the future. I fully expect it would work.

Dynamic Search Boxes in Jquery Mobile

Am not sure on how to do this but I will describe it and hopefully you all can come up with a good solution. I want to have a box (not sure if its an input of search box) that when someone types in the box it pulls values from my database and shows the closest match based on characters being typed in. If the word that is typed by the user is not there then when the form is submitted then the word is added to a database.
Additionally I want to have an add button next to the box, so that if the user wants to add more than one word they can. This means that when the add is clicked a duplicate of the first box appears which does the same thing. The values will be stored in an array.
Any idea how I can go about doing this?

Benefit of using DBComboBox over CombBox?

So I'm messing around with a new project in Delphi 2009 and the default components that can be dropped onto a form for accessing data consist of a SQLConnection, DataSource and SQLQuery. If I add a simple select to the query component, say:
select name from customers
and then drop a DBComboBox on the form and link it up with the DataSource I get a single record in the combo box. After using Google for half and hour to figure out what I was doing wrong it looks like you have to manually add some code to your project which loops through the dataset and adds all the records to the drop down box. Something like:
while not SQLQuery.eof do
begin
DBComboBox.items.add(SQLQuery.fieldbyname('name').asstring);
SQLQuery.next;
end;
And that actually sort of works, but then you get a list in the drop down which you can't actually select anything from. Regardless of the result though I'm wondering why would you even use a DBComboBox if you have to manually add the result of your query to it? Seems to me that if it doesn't automatically populate the db combo box with the result of the query then we might as well be using a non-data-aware component like tcombobox.
I guess what I'm asking is why does it work this way? Isn't the purpose of data aware drag-and-drop controls to minimize the amount of actual written code and speed development? Is there a method that I'm missing that is supposed to make this easier?
A TDBComboBox doesn't get its list of values from the database; it gets its current value from the database. Link it to a field in your dataset, and when you change the active record, the combo box's current value will change. Change the combo box's current value, and the corresponding field's value will change.
If you want to get the list of values from the database as well, then use a TDBLookupComboBox.
This is all covered in the help:
Using TDBListBox and TDBComboBox
Displaying and Editing Data in Lookup List and Combo Boxes
Defining a Lookup List Column
I think you want the TDBLookupComboBox because that allows you to lookup from a list of items where the list comes from a dataset.
In the TDBComboBox, the list is just a TStrings manually filled with data.
--jeroen
DbCombox is a dbaware version of the standard combobox component.

Why would a SharePoint lookup menu require a double-click to select an item?

I have a SharePoint feature which programatically creates 3 lookups in a custom list, one from each of 3 different lists via extremely similar CAML markup.
The only differences in the CAML are the List, ID, Name, DisplayName and StaticName properties yet one of these lookups looks slightly different (has a slightly more "modern" drop-down arrow) than the other two and this same menu requires I double-click in order to select an item instead of single-clicking as I do with the other lookups.
Might anyone have seen this before and have an idea of what I might look into to make this lookup operate as a single-click menu?
The style of dropdown displayed is usually related to the number of items, although it also renders as a standard select element when viewed in firefox.
For any other field type it would make sense to create a custom field control, but due to code that expects things to be named "Lookup", lookup fields are next to impossible to extend.
The best way to customize a specific field is probably with javascript/jquery. When you click on the dropdown arrow, ShowDropdown (in core.js) is called. This creates a select element with options set from the pipe delimited list in the choices attribute of the textbox.
Add some code to the page so that on load EnsureSelect and FilterChoice or similar are called to create the select element. Set properties on the textbox and select elements so that the textbox as hidden and the select element is a visible dropdown. Have SetCtrlFromOpt called on change rather than on blur/double click so that the control that the server will read and save is properly updated.
The same approach could be used to keep the combo box but add a click event to set the value rather than requiring a double click.
How many items has the source list of every lookup field?
Lookup fields shows a "Combo" when the source list has 10 items (I'm not sure if 10 item is the exact limit). When the source list has more than 10 items the lookup field shows a "ListArea" control that works as you said.
I have exactly the same problem. One difference I have noticed is that the one listbox that requires a double-click is a lookup field, whereas the one that doesn't is a choice field with pre-populated choices. Don't know if that helps.

Resources