DBLookupComboBox - How to clear the selected item?

2019-06-21 20:28发布

问题:

What I tried to achieve is like setting ItemIndex to -1 as like in normal ComboBox, so that the selected item will be cleared.

There is no ItemIndex for DBLookupComboBox, and the Text property is read only. So how do I clear the selected item? Please help. Many thanks in advance.

PS: Closing and reopening the DBLookupComboBox->ListSource DataSet does not help.

回答1:

Two ways:

1) at runtime: DbLookupComboBox.KeyValue := null;

2) at design-time: set the DbLookupComboBox.NullValueKey property to DEL (or whatever key you want to use to null the value during runtime)



回答2:

You can use

DBLookupComboBox.KeyValue := -1;


回答3:

DBLookupComboBox represents the value of a field of a database. So you have to clear/change the value of the field to clear/change the value of the DBLookupComboBox by code.



回答4:

if first time you set dblokupcombobox KeyField in property is 'city' //example

if you want to clear selected item you can use this

procedure TFtreset.BitBtn6Click(Sender: TObject);
begin
  dblookupcombobox2.KeyValue:='city';
end;