DBLookupComboBox - How to clear the selected item?

2019-06-21 20:08发布

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.

4条回答
爷的心禁止访问
2楼-- · 2019-06-21 20:49

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)

查看更多
乱世女痞
3楼-- · 2019-06-21 20:53

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楼-- · 2019-06-21 20:59

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;
查看更多
Explosion°爆炸
5楼-- · 2019-06-21 21:00

You can use

DBLookupComboBox.KeyValue := -1;
查看更多
登录 后发表回答