Thanks in advance for your help.
Rolf
--
----------------------------------------------------------------
Rolf Fankhauser, PhD
ETHZ - Federal Institute of Technology Zurich
Institute of Hydromechanics and Water Resources Management
Urban Water Management Division
G 31.3
CH-8093 Zuerich-Hoenggerberg
Switzerland
Tel. +41-1-633 25 07
Fax. +41-1-633 10 61
This way:
unit PBExStringgrid;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
Grids;
const
GM_ACTIVATECELL = WM_USER + 123;
type
TGMActivateCell = record
msg: Cardinal;
aCol, aRow: Integer;
result: Integer;
end;
TPBExStringgrid = class;
TExitCellEvent = Procedure( Sender: TPBExStringgrid; aCol, aRow:
Integer;
Const edittext: String ) of Object;
TPBExStringgrid = class(Tstringgrid)
private
FExitCell: TExitCellEvent;
procedure GMActivateCell( var msg: TGMActivateCell ); message
GM_ACTIVATECELL;
protected
function CreateEditor: TInplaceEdit; override;
procedure ExitCell( const edittext: String; aCol, aRow: Integer );
virtual;
public
procedure ActivateCell( aCol, aRow: Integer );
published
property OnExitCell: TExitCellEvent read FExitCell write FExitCell;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PBGoodies', [TPBExStringgrid]);
end;
Type
TExInplaceEdit = Class( TInplaceEdit )
private
FLastCol, FLastRow: Integer;
Procedure WMKillFocus( Var msg: TMessage ); message WM_KILLFOCUS;
Procedure WMSetFocus( Var msg: TMessage ); message WM_SETFOCUS;
end;
{ TPBExStringgrid }
procedure TPBExStringgrid.ActivateCell(aCol, aRow: Integer);
begin
PostMessage( handle, GM_ACTIVATECELL, aCol, aRow );
end;
function TPBExStringgrid.CreateEditor: TInplaceEdit;
begin
result := TExInplaceEdit.Create( self );
end;
procedure TPBExStringgrid.ExitCell(const edittext: String; aCol, aRow:
Integer );
begin
If Assigned( FExitCell ) Then
FExitCell( self, aCol, aRow, edittext );
end;
procedure TPBExStringgrid.GMActivateCell(var msg: TGMActivateCell);
begin
Col := msg.aCol;
Row := msg.aRow;
EditorMode := true;
InplaceEditor.SelectAll;
end;
{ TExInplaceEdit }
procedure TExInplaceEdit.WMKillFocus(var msg: TMessage);
begin
TPBExStringgrid(Grid).ExitCell( Text, FLastCol, FLastRow );
inherited;
end;
procedure TExInplaceEdit.WMSetFocus(var msg: TMessage);
begin
FLastCol := TPBExStringgrid(Grid).Col;
FLastRow := TPBExStringgrid(Grid).Row;
inherited;
end;
end.
CAVEAT: The OnExitCell event is triggered by a focus change so it has the
same problems as OnExit/OnEnter: you must not do anything in it that
causes another focus change (e.g. showing a message dialog). You can use
the grids ActivateCell method to reactivate the cell. When OnExitCell
fires the grids Col/Row properties already refer to the cell that will
become active.
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!