Index: lcl/grids.pas =================================================================== --- lcl/grids.pas (revision 47402) +++ lcl/grids.pas (working copy) @@ -943,6 +943,7 @@ procedure DrawRow(aRow: Integer); virtual; procedure EditButtonClicked(Sender: TObject); procedure EditordoGetValue; virtual; + procedure EditordoResetValue; virtual; procedure EditordoSetValue; virtual; function EditorCanAcceptKey(const ch: TUTF8Char): boolean; virtual; function EditorIsReadOnly: boolean; virtual; @@ -1217,6 +1218,7 @@ TCustomDrawGrid=class(TCustomGrid) private + FEditorRow, FEditorCol: Integer; FOnColRowDeleted: TgridOperationEvent; FOnColRowExchanged: TgridOperationEvent; FOnColRowInserted: TGridOperationEvent; @@ -1231,6 +1233,7 @@ FOnSetEditText: TSetEditEvent; function CellNeedsCheckboxBitmaps(const aCol,aRow: Integer): boolean; procedure DrawCellCheckboxBitmaps(const aCol,aRow: Integer; const aRect: TRect); + function GetEditorValue(ACol, ARow: Integer): String; protected FGrid: TVirtualGrid; procedure CalcCellExtent(acol, aRow: Integer; var aRect: TRect); virtual; @@ -1243,6 +1246,7 @@ procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); override; procedure DrawCellAutonumbering(aCol,aRow: Integer; aRect: TRect; const aValue: string); virtual; procedure DrawFocusRect(aCol,aRow: Integer; ARect: TRect); override; + function GetCells(ACol, ARow: Integer): string; override; procedure GetCheckBoxState(const aCol, aRow:Integer; var aState:TCheckboxState); virtual; function GetEditMask(aCol, aRow: Longint): string; override; function GetEditText(aCol, aRow: Longint): string; override; @@ -1395,6 +1399,7 @@ property OnStartDrag; property OnTopleftChanged; property OnUTF8KeyPress; + property OnValidateEntry; end; @@ -1506,6 +1511,7 @@ property OnTopleftChanged; property OnUserCheckboxBitmap; property OnUTF8KeyPress; + property OnValidateEntry; end; TCustomStringGrid = class; @@ -6918,6 +6924,12 @@ EditorShow(True); Key := 0; end; + VK_ESCAPE: + begin + EditordoResetValue; + EditorHide; + Key := 0; + end; end; if FEditorKey and (not PreserveRowAutoInserted) then FRowAutoInserted:=False; @@ -7825,6 +7837,21 @@ end; end; +procedure TCustomGrid.EditordoResetValue; +var + msg: TGridMessage; +begin + if (FEditor<>nil) and FEditor.Visible then begin + Msg.LclMsg.msg:=GM_SETVALUE; + Msg.grid:=Self; + Msg.Col:=FCol; + Msg.Row:=FRow; + Msg.Value:=FEditorOldValue; + FEditor.Dispatch(Msg); + SetEditText(Msg.Col, Msg.Row, Msg.Value); + end; +end; + procedure TCustomGrid.EditordoSetValue; var msg: TGridMessage; @@ -9699,6 +9726,21 @@ DrawGridCheckboxBitmaps(aCol, aRow, aRect, aState); end; +function TCustomDrawGrid.GetEditorValue(ACol, ARow: Integer): String; +var + msg: TGridMessage; +begin + if Assigned(Editor) and Editor.Visible then begin + Msg.LclMsg.msg:=GM_GETVALUE; + Msg.grid:=Self; + Msg.Col:=ACol; + Msg.Row:=ARow; + Msg.Value:=''; + Editor.Dispatch(Msg); + Result:=Msg.Value; + end; +end; + procedure TCustomDrawGrid.CalcCellExtent(acol, aRow: Integer; var aRect: TRect); begin // @@ -9759,6 +9801,13 @@ end; end; +function TCustomDrawGrid.GetCells(ACol, ARow: Integer): string; +begin + Result:=inherited GetCells(ACol, ARow); + if (ACol = FEditorCol) and (ARow = FEditorRow) then + Result:=GetEditorValue(ACol, ARow); +end; + procedure TCustomDrawGrid.GetCheckBoxState(const aCol, aRow: Integer; var aState: TCheckboxState); begin @@ -9841,6 +9890,9 @@ begin result:=''; if assigned(OnGetEditText) then OnGetEditText(self, aCol, aRow, Result); + FEditorOldValue:=Result; + FEditorCol:=aCol; + FEditorRow:=aRow; end; procedure TCustomDrawGrid.GridMouseWheel(shift: TShiftState; Delta: Integer);