很简单,第一、如何给combobox或DBcombobox加一个数据库的字段作为其下拉值?我设了dbcombobox的的tablename及field以后,但其下拉值只是第一个记录,不知如何再设才能显示所有记录?第二、如果要显示一个数据库的两个字段作为其下拉值又应该如何设置呢? 另外,DBlookupcombobox与dbcombobox有何区别?本人初学多谢大侠。
调试欢乐多
Tablename.open;
Tablename.first;
while not Tablename.eof do
begin
combobox.items.add (tablename.fieldbyname('字段').asstring);
Tablename1.next
end;
Tablename.first;
combobox.items.add (tablename.fieldbyname('字段').asstring +'|'+
tablename.fieldbyname('字段2').asstring);
利用Dbcombobox在数据输入等一些操作非常不方便。
这时就需要用到TDBLookupCombobox组件,此组件是引用另外一个数据源表中的数据,所以必须对这些数据源进行设置,指定数据源(ListSource)、字段名称(KeyField)和最后显示的字段名称(ListField)如果要显示两个字段,设置时用分号隔开。
介意你用TDBLookupCombobox,非常好用
with adoquery1
begin
close;
sql.clear;
sql.add('select field1 from table where ...');
open;
combobox.clear;
while not eof do
begin
combobox.items.add(fieldbyname('field1').asstring);
next;
end;
close;
end;
2.
with adoquery1
begin
close;
sql.clear;
sql.add('select field1,feild2 from table where ...');
open;
first;
combobox.clear;
while not eof do
begin
combobox.items.add(fieldbyname('field1').asstring);
next;
end;
first;
while not eof do
begin
combobox.items.add(fieldbyname('field2').asstring);
next;
end;
close;
end;3.DBlookupcombobox是显示与之关联的另一个表的字段的信息,而dbcombobox显示本个表字段信息。相应用法看帮助。
begin
combobox.items.add (tablename.fieldbyname('字段').asstring);
Table.next
end;
Table.first;