dbgrid某一列为'部门',怎么把这些部门添加到combobox啊???
以便以后选择用

解决方案 »

  1.   

    var
       I : integer;
       NotExist : boolean;
    begin
       combobox1.Items.Clear;
       with dbgrid1.DataSource.DataSet do
            begin
            first;
            while not Eof do
               begin
               NotExist:=True;
               for I := Combobox1.Items.Count-1 downto 0 do
                   if dbgrid1.Fields[0].value = combobox1.Items[I] then
                      NotExist:=False;
               if NotExist then combobox1.Items.Add(dbgrid1.Fields[0].value);
               next;
               end;
            end;
       //combobox1.ItemIndex:=0;
    end;//上面的Fields[0]是假设你的“部门”位于第一列。如果位于第二列,那么就是Fields[1],依此类推