很简单,第一、如何给combobox或DBcombobox加一个数据库的字段作为其下拉值?我设了dbcombobox的的tablename及field以后,但其下拉值只是第一个记录,不知如何再设才能显示所有记录?第二、如果要显示一个数据库的两个字段作为其下拉值又应该如何设置呢? 另外,DBlookupcombobox与dbcombobox有何区别?本人初学多谢大侠。

解决方案 »

  1.   

    1、
    Tablename.open;
    Tablename.first;
    while not Tablename.eof do
    begin
      combobox.items.add (tablename.fieldbyname('字段').asstring);
      Tablename1.next
    end;
    Tablename.first;
      

  2.   

    2、如果要显示二个字段可以改
    combobox.items.add (tablename.fieldbyname('字段').asstring +'|'+
    tablename.fieldbyname('字段2').asstring);
      

  3.   

    直接用DBComboBox的Lookup表关联到你要的表就对了:)
      

  4.   

    DBlookupcombobox与dbcombobox有何区别?
    利用Dbcombobox在数据输入等一些操作非常不方便。
    这时就需要用到TDBLookupCombobox组件,此组件是引用另外一个数据源表中的数据,所以必须对这些数据源进行设置,指定数据源(ListSource)、字段名称(KeyField)和最后显示的字段名称(ListField)如果要显示两个字段,设置时用分号隔开。
    介意你用TDBLookupCombobox,非常好用
      

  5.   

    不对,用 DBLookupComboBox就行了。
      

  6.   

    1.
      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显示本个表字段信息。相应用法看帮助。
       
      

  7.   

    试试把所有的字段查询出来,放到以一个临时表中temptable,并将其作为一个字段,在用循环将其放到combobox或连接到dbcombobox,当然用dblookupcombobox更容易实现这种功能,只要用里listfield连接到表中就行了.
      

  8.   

    while not Table.eof do
    begin
      combobox.items.add (tablename.fieldbyname('字段').asstring);
      Table.next
    end;
    Table.first;