We help IT Professionals succeed at work.

Named null value in DBLookupComboBox

lavitz asked
I have DBLookupComboBox binded to dataset.
Dataset have record with is named 'All' and have key value NULL (id=NULL, name='ALL')
DBLookupComboBox display this record, but i cant select it.

How i can solve this?
Watch Question

Top Expert 2010
You can use another ID value for this record. For example, 0 or -1.

Or you use another component, which allows to select record with id=NULL. For example, JvDBLookupCombo from JVCL: http://jvcl.delphi-jedi.org/
Top Expert 2010

You probably did not configure datasource info right for the combo property.
It's kind of there but when you select it it does not display in the combo - right ?


Combo display value with null, but i can't select it.
What do you mean 'datasource info' ?
Top Expert 2010

dbcombo has properties : datasource,datafield,key field...
You must set these right...

more details about your problem would be useful, but without that this should work.

Place DataSource component on your form (Data Access TAB in components palette)
Place one dataset component (depends what you use in your app  TTable, Tquery, ADOTable, ADOQuery,....) on your form.
Place DBLookupComboBox component on your form.

Setup Dataset properties needed to connect dataset to DataBase (connection string if that is ADO data set, or DataBase Name if that is TTable component etc.

Setup Datasource dataset property to dataset you use on your form.

Setup DBLookupComboBox  Datasource property to datasource you use on your form. Setup DBLookupComboBox  Datafield property to field in your dataset you want to show in your DBLookupComboBox.

Top Expert 2010

ListSource :YourDataSource;
ListField: YourFieldname;
KeyField: YourFieldname;

These 3 must be set right - only these....


i set them.
List Dataset have data.

id     name
1     'aaaa'
2     'bbbb'
3     'cccc'
Null   'dddd'

in dblookupcombobox all names are displayed correctly. I can select 'aaaa', 'bbbb', 'cccc'. But I cant select 'dddd'

Top Expert 2010

Unfortunatelly, standard dblookupcombobox can't do it.

The simplest way to do what you want is changing ID for 'dddd' to 0 or -1? Is it possible?
Top Expert 2010

what is the datatype for 'id' field (number,autoinc...) ???