如何在程序中动态向combobox的items属性中添加数据,使其与数据库中的数据保持一致?items中的数据要不能重复(数据库中可能会重复).

解决方案 »

  1.   

    with adoquery1 do
    begin
      active:=false;
      active:=true;
      if recordcount>0 then
        begin
          first;
          while not eof do
           begin
           combobox1.items.add(trim(fieldbyname('field').asstring));
           next;
           end;
        combobox1.itemindex:=0;
        end;
    end;
    ________________________________
    做个调查,关于软件界面
    http://expert.csdn.net/Expert/TopicView2.asp?id=1649010
    谢谢关注
      

  2.   

    adoquery1.sql.clear;
    adoquery1.sql.add('select field1 from table1 group by field1');
    with adoquery1 do
    begin
      active:=true;
      if recordcount>0 then
        begin
          first;
          repeat
           combobox1.items.add(adoquery1field1.asstring);
           next;
          until eof ;
        combobox1.itemindex:=0;
        end;
    end;
      

  3.   

    其实用table控件也可以,当然那combobox的items的数据内容就不是查询出来的,是数据库中的某个字段内容,也挺好用的:
    var i,j:integer;
    begin
    j:=table1.recordcont;
    for i:=0 to j-1 do
    table1.moveby(i);
    combobox1.items.add(table1.fieldbyname('field'));//field为数据库中的某字段
    end;我就这样添加combobox的items的值,也挺好用的.
      

  4.   

    小错误,更正:var i,j:integer;
    begin
    j:=table1.recordcont;
    for i:=0 to j-1 do
    begin
    table1.moveby(i);
    combobox1.items.add(table1.fieldbyname('field'));//field为数据库中的某字段
    end;
    end;