unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, NxEdit6, NxGridView6, NxColumns6, NxControls6, NxCustomGrid6, NxVirtualGrid6,
  NxGrid6, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    NextGrid61: TNextGrid6;
    NxTextColumn61: TNxTextColumn6;
    NxReportGridView61: TNxReportGridView6;
    NxTextColumn62: TNxTextColumn6;
    NxTrackbarColumn61: TNxTrackbarColumn6;
    grLog: TNextGrid6;
    NxReportGridView62: TNxReportGridView6;
    coCol: TNxNumberColumn6;
    coRow: TNxNumberColumn6;
    coText: TNxTextColumn6;
    coEvent: TNxTreeColumn6;
    coExtra: TNxTextColumn6;
    Button1: TButton;
    procedure NextGrid61GetInplaceEdit(Sender: TObject; ACol, ARow: Integer; var InplaceEdit: INxInplaceEdit);
    procedure FormCreate(Sender: TObject);
    procedure NextGrid61BeforeEdit(Sender: TObject; ACol, ARow: Integer; var Accept: Boolean; var Text: WideString);
    procedure NextGrid61EditEnter(Sender: TObject; ACol, ARow: Integer);
    procedure NextGrid61AfterEdit(Sender: TObject; ACol, ARow: Integer; Text: WideString);
    procedure NextGrid61AcceptEdit(Sender: TObject; ACol, ARow: Integer; var Text: WideString; var Accept,
      CanLeave: Boolean);
    procedure NextGrid61EditExit(Sender: TObject; ACol, ARow: Integer);
    procedure Button1Click(Sender: TObject);
    procedure NextGrid61InplaceEditChange(Sender: TObject);
    procedure NextGrid61InplaceEditInsert(Sender: TObject; ACol, ARow: Integer; Component: TComponent);
  private
    FLastEditIndex: Integer;
    procedure AddLog(Event: WideString; ACol, ARow: Integer; Text: WideString; Extra: WideString = '');
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AddLog(Event: WideString; ACol, ARow: Integer; Text: WideString; Extra: WideString = '');
begin
  if FLastEditIndex <> -1 then
  begin

    with grLog.AddChildRow(FLastEditIndex).Cells do
    begin
      Item[coEvent.Index].AsString := Event;
      Item[coCol.Index].AsInteger := ACol;
      Item[coRow.Index].AsInteger := ARow;
      Item[coText.Index].AsString := Text;
      Item[coExtra.Index].AsString := Extra;
    end;

  end else
  begin

    with grLog.AddRow.Cells do
    begin
      Item[coEvent.Index].AsString := Event;
      Item[coCol.Index].AsInteger := ACol;
      Item[coRow.Index].AsInteger := ARow;
      Item[coText.Index].AsString := Text;
      Item[coExtra.Index].AsString := Extra;
    end;

  end;

  grLog.SelectLastAddedRow;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  grLog.ClearRows;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FLastEditIndex := -1;
  NextGrid61.AddCells([
    '', 'Lary', '43',
    '', 'Jim', '0',
    '', 'Ann', '0'
  ], [0, 1, 2]);
end;

procedure TForm1.NextGrid61AcceptEdit(Sender: TObject; ACol, ARow: Integer; var Text: WideString; var Accept,
  CanLeave: Boolean);
begin
  AddLog('OnAcceptEdit', ACol, ARow, Text, 'var Accept');
end;

procedure TForm1.NextGrid61AfterEdit(Sender: TObject; ACol, ARow: Integer; Text: WideString);
begin
  AddLog('OnAfterEdit', ACol, ARow, Text);
end;

procedure TForm1.NextGrid61BeforeEdit(Sender: TObject; ACol, ARow: Integer; var Accept: Boolean; var Text: WideString);
begin
  AddLog('OnBeforeEdit', ACol, ARow, Text, 'var Accept');
  FLastEditIndex := grLog.LastVisibleRow;
end;

procedure TForm1.NextGrid61EditEnter(Sender: TObject; ACol, ARow: Integer);
begin
  AddLog('OnEditEnter', ACol, ARow, '');
end;

procedure TForm1.NextGrid61EditExit(Sender: TObject; ACol, ARow: Integer);
begin
  AddLog('OnEditExit', ACol, ARow, '');
  FLastEditIndex := -1;
end;

procedure TForm1.NextGrid61GetInplaceEdit(Sender: TObject; ACol, ARow: Integer; var InplaceEdit: INxInplaceEdit);
begin
  AddLog('OnGetInplaceEdit', ACol, ARow, '', 'var InplaceEdit');

  if ACol = NxTextColumn61.Index then InplaceEdit := TNxSpinEdit6.Create(Self);

  if ACol = NxTrackbarColumn61.Index then
  begin
    InplaceEdit := TNxComboBox6.Create(Self);
    with InplaceEdit as TNxComboBox6 do
    begin
      Items.Add('10');
      Items.Add('20');
      Items.Add('30');
      Items.Add('40');
      Items.Add('50');
      Items.Add('60');
      Items.Add('70');
      Items.Add('80');
      Items.Add('90');
      Items.Add('100');
    end;
  end;

end;

procedure TForm1.NextGrid61InplaceEditChange(Sender: TObject);
begin
  AddLog('OnInplaceEditChange', NextGrid61.EditingCell.X, NextGrid61.EditingCell.Y, NextGrid61.InplaceEdit.Text);
end;

procedure TForm1.NextGrid61InplaceEditInsert(Sender: TObject; ACol, ARow: Integer; Component: TComponent);
begin
  AddLog('OnInplaceEditInsert', NextGrid61.EditingCell.X, NextGrid61.EditingCell.Y, NextGrid61.InplaceEdit.Text);
  grLog.Cell[0, grLog.LastAddedRow].Hint := 'InplaceEdit.Parent := Grid';
end;

end.
