Drop a TFNCTMSDataGrid and a Tbutton in a new form and use the following source
Double click in the row 1, column 1 and write something.
After that press directly the button to insert a new row.
The value entered in the first row is lost
This due to the call of SelectCell & EditCell to begin direct edit without needing a double click.
What to call/do before adding a new row to ensure that all processing for an entered value is done?
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VCL.TMSFNCTypes, VCL.TMSFNCUtils,
VCL.TMSFNCGraphics, VCL.TMSFNCGraphicsTypes, System.Rtti,
VCL.TMSFNCDataGridCell, VCL.TMSFNCDataGridData, VCL.TMSFNCDataGridBase,
VCL.TMSFNCDataGridCore, VCL.TMSFNCDataGridRenderer, VCL.TMSFNCCustomControl,
VCL.TMSFNCDataGrid, Vcl.StdCtrls;
type
Ttest=class(tobject)
v:string;
end;
TForm3 = class(TForm)
TMSFNCDataGrid1: TTMSFNCDataGrid;
Button1: TButton;
procedure TMSFNCDataGrid1CellEditGetData(Sender: TObject;
ACell: TTMSFNCDataGridCellCoord;
AInplaceEditor: TTMSFNCDataGridInplaceEditor;
var AValue: TTMSFNCDataGridCellValue);
procedure TMSFNCDataGrid1CellEditSetData(Sender: TObject;
ACell: TTMSFNCDataGridCellCoord;
AInplaceEditor: TTMSFNCDataGridInplaceEditor;
var AValue: TTMSFNCDataGridCellValue);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormShow(Sender: TObject);
begin
with TMSFNCDataGrid1 do begin
RowCount:=2; ColumnCount:=3;
Objects[0,1]:=ttest.Create;
end;
end;
procedure TForm3.Button1Click(Sender: TObject);
var i:integer; dd:TTMSFNCDataGridCellCoord;
begin i:=TMSFNCDataGrid1.EditingCell.Row+1;
if i=0 then inc(i);
TMSFNCDataGrid1.InsertRow(i);
TMSFNCDataGrid1.Objects[0,i]:=ttest.Create;
dd.Row:=i; dd.column:=1;
TMSFNCDataGrid1.SelectCell(dd);
TMSFNCDataGrid1.EditCell(dd);
end;
procedure TForm3.TMSFNCDataGrid1CellEditGetData(Sender: TObject;
ACell: TTMSFNCDataGridCellCoord; AInplaceEditor: TTMSFNCDataGridInplaceEditor;
var AValue: TTMSFNCDataGridCellValue);
begin
if (acell.Row>0) and (acell.Column=1) then
avalue:=ttest(TMSFNCDataGrid1.Objects[0,acell.row]).v;
end;
procedure TForm3.TMSFNCDataGrid1CellEditSetData(Sender: TObject;
ACell: TTMSFNCDataGridCellCoord; AInplaceEditor: TTMSFNCDataGridInplaceEditor;
var AValue: TTMSFNCDataGridCellValue);
begin
if (acell.Row>0) and (acell.Column=1) then
ttest(TMSFNCDataGrid1.Objects[0,acell.row]).v:=avalue.AsString;
end;
end.