应该用dbComboBox或者DbLookupComboBox

解决方案 »

  1.   

    unit U_CommFunc;interface
    uses
      db,dbclient,stdctrls,classes,Sysutils,Dialogs;
      procedure GetComboBoxList(DataSet:TDataSet;FieldName:string;ComboBox:TComboBox);
    implementationprocedure GetComboBoxList(DataSet:TDataSet;FieldName:string;ComboBox:TComboBox);
    {本过程为目标ComboBox加载数据源DataSet中
    字段名为FieldName的所有数据项的list列表}
    var
      StringList: TStrings;
      FieldValue:string;
    begin
      if DataSet.Fields.FindField(FieldName) = nil then
      begin
        showmessage('错误:指定字段'+FieldName+'没找着!');
        exit;
      end;
      StringList := TStringList.Create;
      try
        with  DataSet do
        begin
          if not active then open;
          first;
          while not eof do
          begin
            FieldValue:=trim(FieldByName(FieldName).asstring);
            StringList.Add(FieldValue);
            next;
          end;
          first;
        end;
        with ComboBox do begin
          Width := 210;
          Items.Assign(StringList);
          ItemIndex := 0;
          ComboBox.Style:=csDropDownList;
        end;
      finally
        StringList.free;
      end;
    end;end.