你可以使用StringGrid1控件,它就像一个数组来存放数据,等到你输入完后就可以自己处理这些数据了。

解决方案 »

  1.   

    在你的dbgrid相关的query里,设置updatecache,用一个UpdateSql来更新数据,这样就可以行控制存到数据库
      

  2.   

    在DBGRID中取到我刚刚输入数据~~好像不是那么好取得的~~~
      

  3.   

    ADOQuery的LockType属性设置为ltBatchOptimistic~~
    这样在DBGrid中输入的数据暂时是存到内存里面的~~
    在想要存到数据库中的时候~使用ADOQuery.UpdateBatch(Arall);就可以把数据存到数据库中~
      

  4.   

    当然~如果你想在输入一条新纪录以后就保存到数据库中~使用ADOQuery的默认属性即可~
      

  5.   

    lifenqidelphi(血) ~~~~~~~~~~~~滚~~~~~~~~~
      

  6.   

    要取刚输入的数据,大概思路如下:
    在DBGrid的控件数组里找TEdit类的控件,那个就是你正在编辑数据的控件,它的Text属性自然就是刚才编辑的数据了。
    现在我机器里没有Delphi了,所以写出来的代码不能调试,不过基本上应该是这样的:var
      ValueEditing: string;
      i: integer;
    begin
      with DBGrid1 do
        for i := 0 to ComponentCount - 1 do
          if Components[i] is TEdit then
          begin
            ValueEditing := TEdit(Components[i]).Text;
            ShowMessage('这个就是刚才编辑的数据:' + ValueEditing);
            Break;
          end;
    end;
      

  7.   

    zengyufeng(御风) ~~不是TEdit阿~~
      

  8.   

    zengyufeng这位老兄,我试过了,但是好象不是tEDIT,你再想想好吗?我现在很急
      

  9.   

    呵呵~是TDBGridInPlaceEdit~~~
      

  10.   

    所有编辑类的控件都是从TEdit派生出来的,所以可以把它视为TEdit
      

  11.   

    还有要注意的是:这段代码你只能在Timer事件里或其他不会让DBGrid失去焦点的地方进行测试,因为一旦DBGrid失去焦点,它就会把正在编辑数据的控件释放掉,你就找不到那个Edit了
      

  12.   

    要取得刚才输入的数据:dbgrid1.fields【0】。asstring
    要自己控制保存需设置query的cachedupates设置为true即可
      

  13.   

    我把这段程序当到TIMER事件中:
    var ValueEditing: string;
        i: integer;
    begin  with Dbg_gz do
      for i := 0 to ComponentCount - 1 do
      begin
          if Components[i] is TEdit then
          begin
            ValueEditing := TEdit(Components[i]).Text;
            ShowMessage('这个就是刚才编辑的数据:' + ValueEditing);
            Break;
          end;
      end;
    end;
    然后又在DBGRID这个ColExit(Sender: TObject);中调用,还是不行
      

  14.   

    我试过了~在CellClick中~~不起作用~~
      

  15.   

    这个问题我也遇到过,我是为了在dbgrid中输入数值的时候就能自动的查询,而dbgrid又没有象Tedit那样的onchange的事件。
    还记得Tstringgrid中有个onSetEditText事件吗,他其实就象Tedit的onchange事迹一样,可以感知输入数据的直接变化(还没有update到数据库里),所以可以你可以重新做一个dbgrid让他继承TstringGRid的onsetedittext事件,其实只要重载它就可以了。代码如下:(里面还有个text的属性,对你没用的,我懒的改了,hehe )unit DBGrid_ex;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Grids, DBGrids;
     {Messages, Windows, MultiMon, Classes, Sysutils, Graphics, Menus, CommCtrl,
      Imm, ImgList, ActnList}
    type
      TDBGrid_ex = class(TDBGrid)
      private
        {FEditText: string;}
        FOnSetEditText: TSetEditEvent;
        { Private declarations }
      protected
       function GetText: TCaption;
       function GetTextLen: Integer;
       function GetTextBuf(Buffer: PChar; BufSize: Integer): Integer;
       function Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
       procedure SetText(const Value: TCaption);
       procedure SetTextBuf(Buffer: PChar);
       procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
        { Protected declarations }
      public
      constructor create(Aowner:Tcomponent);override;
        { Public declarations }
      published
       property Text: TCaption read GetText write SetText;
       property OnSetEditText: TSetEditEvent read FOnSetEditText write FOnSetEditText;
        { Published declarations }
      end;
    procedure Register;implementationconstructor TDBGrid_ex.create(Aowner: TComponent);
        begin
          inherited Create(AOwner);
        end;function TDBGrid_ex.Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
    var
      Message: TMessage;
    begin
      Message.Msg := Msg;
      Message.WParam := WParam;
      Message.LParam := LParam;
      Message.Result := 0;
      if Self <> nil then WindowProc(Message);
      Result := Message.Result;
    end;function TDBGrid_ex.GetTextLen: Integer;
    begin
      Result := Perform(WM_GETTEXTLENGTH, 0, 0);
    end;function Tdbgrid_ex.GetTextBuf(Buffer: PChar; BufSize: Integer): Integer;
    begin
      Result := Perform(WM_GETTEXT, BufSize, Longint(Buffer));
    end;function Tdbgrid_ex.GetText: TCaption;
    var
      Len: Integer;
    begin
      Len := GetTextLen;
      SetString(Result, PChar(nil), Len);
      if Len <> 0 then GetTextBuf(Pointer(Result), Len + 1);
    end;
    procedure Tdbgrid_ex.SetTextBuf(Buffer: PChar);
    begin
      Perform(WM_SETTEXT, 0, Longint(Buffer));
      Perform(CM_TEXTCHANGED, 0, 0);
    end;procedure Tdbgrid_ex.SetText(const Value: TCaption);
    begin
      if GetText <> Value then SetTextBuf(PChar(Value));
    end;procedure TdbGrid_ex.SetEditText(ACol, ARow: Longint; const Value: string);
    begin
      inherited;
      if Assigned(FOnSetEditText) then FOnSetEditText(Self, ACol, ARow, Value);
    end;procedure Register;
    begin
      RegisterComponents('Data Controls', [TDBGrid_ex]);
    end;end.
      

  16.   

    TO:kofxdm(八稚) ~~~好厉害!!果然正确!!佩服~~
      

  17.   

    TO ltz
    你不是要取输入到dbgrid里的值吗(是指还没有update时的数据)。
    在procedure SetEditText(ACol, ARow: Longint; const Value: string);里不是有value吗,这个值就是你想要的数据呀。这个value是随着你的输入而改变的。
    如果你是不会安装控件的话,那去查查关于控件制作的书籍就可以搞定。
     
      

  18.   

    ltz():你最后如何解决的?我现在也被和你同样的问题困扰着!
    盼望你告诉我。[email protected]