比如我有一个表,用dbgrid显示出来这个表,其中一个字段名是name,name下面有chen,li,yang等。如何才能在listbox中将这些名字显示出来?

解决方案 »

  1.   

    这是我以前写的代码,你参考一下。    listbox1.Clear;
        with itemlot do
         begin
          close;
          sql.Clear;
          sql.Add('select mol_itm_code,mol_lotnum from renywip where  mop_opr_code in(select wws_routing from tblwipworkstd where cost_routing=:A) ');
          sql.Add('order by mol_itm_code,mol_lotnum');
          Parameters.ParamByName('A').Value:=trim(combobox1.Text);
          open;
         end;
          if itemlot.RecordCount>0 then
           while not itemlot.Eof do
           begin
             listbox1.Items.Add(itemlot.FieldValues['mol_itm_code']+'___'+itemlot.FieldValues['mol_lotnum']);
             itemlot.Next;
           end;
      

  2.   


    listbox1.items.clear;
    adoquery1.close;
    adoquery1.connection:=adoconnection1;
    adoquery1.sql.clear;
    adoquery1.sql.add(select distinct name from tablename);
    adoquery1.open;
    while not adoquery1.eof do
    begin
      s:=adoquery1.fieldbyname('name').asstring;
      listbox1.items.add(s);
      adoquery1.next;
    end;