如题!!!

解决方案 »

  1.   

    每一行都不同?
    那就在DBGrid连的AdoQuery或者Query的AfterScroll事件里动态添加好了。
    先清空,然后添加指定内容。
      

  2.   

    谢谢各位,我也刚好碰到这类问题!~~~是不是可以用dblookup 控件 !~~~
      

  3.   

    下面这个可以实现,自己研究看看
    使用dbcombobox控件到dbgrid
    将数据库中数据加到dbcombobox中
    或者直接在dbcombobox中加入应选择的项
    在窗体上放一个DBComboBox,Visible为False;
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DBCtrls, Grids, DBGrids, DB, DBTables;type
      TForm1 = class(TForm)
        Table1: TTable;
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        DBComboBox1: TDBComboBox;
        DBComboBox2: TDBComboBox;
        DBComboBox3: TDBComboBox;
        procedure DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
          Field: TField; State: TGridDrawState);
        procedure DBGrid1ColExit(Sender: TObject);
        procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    begin
      if (gdFocused in State) then
      begin
         if (Field.FieldName = DBCombobox1.DataField) then
         begin
           DBCombobox1.Left :=Rect.Left + DBgrid1.Left;
           DBCombobox1.Top := Rect.Top + DBgrid1.Top;
           DBCombobox1.Width := Rect.Right - Rect.Left;
           DBCombobox1.Visible :=True;
         end;
         if (Field.FieldName = DBCombobox2.DataField) then
         begin
           DBCombobox2.Left :=Rect.Left + DBgrid1.Left;
           DBCombobox2.Top := Rect.Top + DBgrid1.Top;
           DBCombobox2.Width := Rect.Right - Rect.Left;
           DBCombobox2.Visible :=True;
         end;     if (Field.FieldName = DBCombobox3.DataField) then
         begin
           DBCombobox3.Left :=Rect.Left + DBgrid1.Left;
           DBCombobox3.Top := Rect.Top + DBgrid1.Top;
           DBCombobox3.Width := Rect.Right - Rect.Left;
           DBCombobox3.Visible :=True;
         end;
      end;
    end;procedure TForm1.DBGrid1ColExit(Sender: TObject);
    begin
      if DBGrid1.SelectedField.FieldName = DBCombobox1.DataField then
      begin
        DBCombobox1.Visible := false;
      end;
      if DBGrid1.SelectedField.FieldName = DBCombobox2.DataField then
      begin
        DBCombobox2.Visible := false;
      end;
      if DBGrid1.SelectedField.FieldName = DBCombobox3.DataField then
      begin
        DBCombobox3.Visible := false;
      end;
    end;procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (key <> chr(9)) then
      begin
       if (DBGrid1.SelectedField.FieldName = DBCombobox1.DataField ) then
       begin
         DBCombobox1.SetFocus;
         SendMessage(DBCombobox1.Handle,WM_CHAR,word(Key),0);
       end;   if (DBGrid1.SelectedField.FieldName = DBCombobox2.DataField ) then
       begin
         DBCombobox2.SetFocus;
         SendMessage(DBCombobox1.Handle,WM_CHAR,word(Key),0);
       end;   if (DBGrid1.SelectedField.FieldName = DBCombobox3.DataField ) then
       begin
         DBCombobox3.SetFocus;
         SendMessage(DBCombobox1.Handle,WM_CHAR,word(Key),0);
       end;
      end;
    end;end.
      

  4.   

    在每个DBCombobox中设置不同的下拉内容下拉内容,或者读数据库中的,随你了