在form的create事件中用Tadoquery向14个组合框添加同一个表的同个字段的所有值。  
注:  该form中一共有16个组合框,combobox1~14是添加同一个表的同个字段的所有值。    另两个可不能加上述的值

解决方案 »

  1.   

    先用adoquery取得数据,然后给combobox1赋值,然后让combobox2到combobox14
    的items和combobox1一样。--------------------
    另两个可不能加上述的值  
    --------------------
    是什么意思?
      

  2.   

    function add;
    var
      i: integer;
    begin
      adoquery1.open;
      for i := 1 to to 14 do
      begin
        (findcomponent('combobox'+inttostr(i)) as tcombobox).items.add(adoquery1.fieldbyname('').asstring);
      end;
      combobox15.items.add('');
      combobox16.items.add('');
    end;
      

  3.   

    for ii:= 1 to 14 do
    begin
      TComboBox.FindComponent('combobox'+IntToStr(ii)).Items.Add('123');
      TComboBox.FindComponent('combobox'+IntToStr(ii)).Items.Add('456');
    end;
      

  4.   

    求助
    http://expert.csdn.net/Expert/topic/1381/1381664.xml?temp=.9872248
      

  5.   

    同意   whycats(雪狐) 的
      

  6.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      I: Integer;
    begin
      With AdoQuery do
      begin
        Open;
        while Not Eof do
        begin
          ComboBox1.Items.Add(FieldByName('Field1').AsString);
          Next;
        end;      
      end; 
      for I := 2 to 14 do
        TComboBox(FindComponent('ComboBox' + IntToStr(I))).Items.Assign  (ComboBox1.Items);
    end;
      

  7.   

    1.先在设计时把要赋值的14个的tag设为1;
    var
      I: Integer;
      ls:TStrings;
      Temp: TComponent;
    begin
      ls:=TStrings.Create;
      try
         With AdoQuery do
         begin
           Open;
           while Not Eof do
           begin
             ls.Add(FieldByName('Field1').AsString);
             Next;
           end;
           close;
         end;
         For i:=0 to ComponentCount -1  do
         begin
            Temp := Components[I];
           if (Temp is TComboBox) then
             if (Temp as TComboBox).tag=1 then
                (Temp as TComboBox).Items.Assign(ls);
         end;
      Finally
       ls.free;
      end;
      

  8.   

    procedure TForm1.Button4Click(Sender: TObject);
    var i :integer;
    begin
       ADOQuery1.First;
       while not ADOQuery1.Eof do
       begin
          ComboBox1.Items.Add(ADOQuery1.FieldByName('name').AsString);
       ADOQuery1.Next;
       end;
       for i:=0 to self.ComponentCount-1 do
       begin
          if Components[i]<>Combobox1 then
          begin
             if Components[i].ClassType = TComboBox then
             TComboBox(Components[i]).Items.Assign(ComboBox1.Items);
          end;
       end;
    end;
      

  9.   

    我的速度快,不管你有几多个ComboBox总一样的。
    循环的次数又少!
      

  10.   

    简单而有效:procedure TForm1.Button4Click(Sender: TObject);
    var i :integer;
    begin
       ADOQuery1.Open;
       ADOQuery1.First;
       while not ADOQuery1.Eof do
       begin
          ComboBox1.Items.Add(ADOQuery1.FieldByName('name').AsString);
          ADOQuery1.Next;
       end;for i:= 2 to 14 do
    begin
      TComboBox(FindComponent('ComboBox' + IntToStr(I))).Items:=combobox1.items;
    end;