没错,是ComboBox, 我的代码如下: procedure Tguahaofeishezhi.FormCreate(Sender: TObject); var i:integer; ATmpStr:string; begin ReadmeIni(); with add_guahaofei do begin if Active then Close; ConnectionString:=ctLinkString; CommandText:='select leibie,shoufeibiaozhun,gongbenfei from yy_guahaofei'; Open; end; cb_shoufeileibie.Clear; add_guahaofei.First; //实现下拉列表。 for i:= 1 to add_guahaofei.RecordCount do begin ATmpStr:=add_guahaofei.FieldByName('leibie').AsString; cb_shoufeileibie.Items.Append(ATmpStr); add_guahaofei.Next; end; end;
ComboBox不是Data aware(数据感知)控件,所以需要自己代码控制的
Combobox1.items.clear;with query1 do begin close; Unprepare; sql.clear; databasename :=database1.databasename; sql.text :=...; try Prepare; Open;
First; While not Eof do begin combobox1.items.add(Fields[0].asstring); next; end; end; query1.close;
属性设置
ListSource为ADOQuery1.DataSource
ListField为us_name
KeyFeild为ID
在用户选择相应条目的时该条目的ID号:
DBLookupComboBox2.KeyValue
我的代码如下:
procedure Tguahaofeishezhi.FormCreate(Sender: TObject);
var
i:integer;
ATmpStr:string;
begin
ReadmeIni();
with add_guahaofei do
begin
if Active then Close;
ConnectionString:=ctLinkString;
CommandText:='select leibie,shoufeibiaozhun,gongbenfei from yy_guahaofei';
Open;
end;
cb_shoufeileibie.Clear;
add_guahaofei.First; //实现下拉列表。
for i:= 1 to add_guahaofei.RecordCount do
begin
ATmpStr:=add_guahaofei.FieldByName('leibie').AsString;
cb_shoufeileibie.Items.Append(ATmpStr);
add_guahaofei.Next;
end;
end;
begin
close;
Unprepare;
sql.clear;
databasename :=database1.databasename;
sql.text :=...; try
Prepare;
Open;
First;
While not Eof do
begin
combobox1.items.add(Fields[0].asstring);
next;
end;
end;
query1.close;