I have a TDBLookupComboBox
showing a TStringField
of kind fkLookup
, which allows Null
values (from a nullable Integer database column).
The dropdown list displays the items from the assigned LookupDataSet
, which comes from a joined table. If the field is Null
, none of the list items are displayed, the combobox is empty. If the field has a value, the correct description is shown.
I can reset it to Null
by pressing the assigned NullValueKey
.
That's all ok, but the users prefer using the mouse. So I could provide a clear button, but I think an additional row on top of the list would be much better. How can I do that?
This is not exactly what was requested, but it might be the better solution for developers having a DevExpress VCL ExpressEditors subscription: there is a hidden feature in
TcxDBLookupComboBox
which can provide a nice clear button inside the combobox!It works exactly like in the
TcxButtonEdit
, where you can add buttons at designtime, just that thisButtons
property isn't exposed inTcxDBLookupComboBox
, so it can only be set at runtime :(This might also work with other edit controls, however, at least with TcxDBSpinEdit it does not.
You can use as your
LookupDataSet
a query with the next SQL (Firebird syntax)However, in this implementation
clear
item will be at the end of the list.Added after our discussion in the chat
I'm afraid we never reach to have null-value field's behavior like normal fields, because null is not a value, as was correctly mentioned here: https://petercai.com/null-is-not-a-value/ . We can only make some workarounds for it.
For example, we can see custom displayed value for null such as
SELECT CASE WHEN OurField IS NULL THEN '(empty)' ELSE OurField END AS OurField
. And we can set null with artificial menu item. But this is not a full, complex solution.You can put the empty row in your query, and if you need it sorted you can make it appear at the top in your list like this:
The
sort
column will make it appear at the top, after that you can sort on whatever you need.