如题

解决方案 »

  1.   

    在Tdateset中编辑fields
    add field,新建一个字段,里面可以设置。
      

  2.   

    在Tdateset中编辑fields
    add field,新建一个字段,里面可以设置。
      

  3.   

    你可以在DrawCell的时候,动态生成一个CheckBox,然后根据Cell的位置和大小调整CheckBox的位置和大小,这样就在Cell里面显示了一个CheckBox啊。下面是在Cell中放入DBComboBox的代码,你可以参考然后改成你所要的CheckBox。主要是位置的调整,还有多个CheckBox的生成和管理
    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.
    这是在DBGrid放一个DBComboBox的例子,你可以改改就好了。
      

  4.   

    你在dbgrid.column[0].picklist中设置两项是、否应该会方便一点。
      

  5.   

    To:netlib(河外孤星) filed 是动态创建的,怎么设置?
    To:debussy(debussy) 如果我要有30 个X 2000行 这么多的checkbox 那效率会不会太低?
    还有没有简单的方法?
      

  6.   

    哇~~有那么多阿,那就只是显示的时候创建罗,没显示了就释放,你的屏幕不可能大到可以同时显示6万个Cell罢?
      

  7.   

    有这么多,晕了吧?
    要做得像ACCESS 表里面那个勾,该怎么搞呢?
      

  8.   

    不用那么复杂吧!
    在Tquery字段编辑器中直接赋字段的displayvalues的值即可;
    用下面这个值即可:
    √;×
      

  9.   

    to jixinfa(DELHPI程序员):
    这样可以实现动态变化吗?我说的意思是能不能实现点一下则变化一回的功能啊?