to cuigw:
unit MyStringGrid;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;
type
TMyStringGrid = class(TStringGrid)
private
FOnCellEditExit: TNotifyEvent;
protected
function CreateEditor: TInplaceEdit; override;
published
property OnCellEditExit: TNotifyEvent read FOnCellEditExit
write FOnCellEditExit;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TMyStringGrid]);
end;
type
TMyInplaceEdit = class(TInplaceEdit)
private
FOnEditExit: TNotifyEvent;
procedure WMKillFocus(var Msg: TWMKillFocus); message WM_KILLFOCUS;
protected
property OnEditExit: TNotifyEvent read FOnEditExit write FOnEditExit;
end;
{ TMyInplaceEdit }
//当 cell 处于编辑状态而将要失去焦点时触发该消息
procedure TMyInplaceEdit.WMKillFocus(var Msg: TWMKillFocus);
begin
if Assigned(FOnEditExit) then
FOnEditExit(Self); //这里可以改成做在失去焦点前你想要完成的处理
inherited; //如果不调用 inherited 则不会失去焦点
end;
{ TMyStringGrid }
function TMyStringGrid.CreateEditor: TInplaceEdit;
begin
Result := TMyInplaceEdit.Create(Self);
TMyInplaceEdit(Result).OnEditExit := FOnCellEditExit;
end;
end.
主要是重载 TInplaceEdit ,我试了可以的。为 StringGrid 加了一个 CellEditExit 事件,
知道了原理,你自己可以作修改。