你可以使用StringGrid1控件,它就像一个数组来存放数据,等到你输入完后就可以自己处理这些数据了。
解决方案 »
- ReportMachine安装成功后,打开有RM控件的项目提示Error reading RMReport1.PreviewOptions.RulerUnit: Property PreviewOpt
- 了解GSM设备的请进来
- 为什么 ado 行 而 dbexpress 不行?
- c/s数据库导出的问题--在线等待,解决了就给分,分不够还可以加
- 在Paradox中如何获取指定行的记录(急)
- 用什么软件以16进制数查看文件的数据??
- 怎么知道是最后一条记录?
- 怎样调用拨号连接对话框??
- 很easy的问题,但是怎样实现更佳(速度,简洁),敬请请大家关注!
- Delphi5中有TRegistry类吗?
- Dsgnlntf.dcu是一个什么文件。
- DbGrid中有针对某个字段的OnChange事件吗?
这样在DBGrid中输入的数据暂时是存到内存里面的~~
在想要存到数据库中的时候~使用ADOQuery.UpdateBatch(Arall);就可以把数据存到数据库中~
在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;
要自己控制保存需设置query的cachedupates设置为true即可
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);中调用,还是不行
还记得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.
你不是要取输入到dbgrid里的值吗(是指还没有update时的数据)。
在procedure SetEditText(ACol, ARow: Longint; const Value: string);里不是有value吗,这个值就是你想要的数据呀。这个value是随着你的输入而改变的。
如果你是不会安装控件的话,那去查查关于控件制作的书籍就可以搞定。
盼望你告诉我。[email protected]