unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, NxColumnClasses, NxColumns, NxScrollControl,
  NxCustomGridControl, NxCustomGrid, NxGrid, ImgList;

type
  TForm1 = class(TForm)
    NextGrid1: TNextGrid;
    NxTreeColumn1: TNxTreeColumn;
    Button1: TButton;
    Button2: TButton;
    NxCheckBoxColumn1: TNxCheckBoxColumn;
    NxImageColumn1: TNxImageColumn;
    ImageList1: TImageList;
    NxProgressColumn1: TNxProgressColumn;
    CheckBox1: TCheckBox;
    Button3: TButton;
    Button5: TButton;
    CheckBox2: TCheckBox;
    Button4: TButton;
    Button6: TButton;
    Button7: TButton;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    NxTextColumn1: TNxMemoColumn;
    Button8: TButton;
    Button9: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure NextGrid1SelectCell(Sender: TObject; ACol, ARow: Integer);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Math;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  NextGrid1.AddRow();
  NextGrid1.Cell[2, NextGrid1.LastAddedRow].AsString := 'Top Level';
  NextGrid1.Cell[3, NextGrid1.LastAddedRow].AsInteger := Random(100);
  NextGrid1.SelectLastRow;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if CheckBox2.Checked
    then NextGrid1.AddChildRow(NextGrid1.SelectedRow, crLast)
      else NextGrid1.AddChildRow(NextGrid1.SelectedRow, crFirst);
      
  NextGrid1.Cell[2, NextGrid1.LastAddedRow].AsString := 'Child Row';
  NextGrid1.Cell[3, NextGrid1.LastAddedRow].AsInteger := Random(100);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;
  Button2.Enabled := False;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if (Sender as TCheckBox).Checked then
    NextGrid1.Options := NextGrid1.Options + [goGrid] else
      NextGrid1.Options := NextGrid1.Options - [goGrid]
end;

procedure TForm1.NextGrid1SelectCell(Sender: TObject; ACol, ARow: Integer);
begin
  if ACol = 1 then
  begin
    NextGrid1.Cell[ACol, ARow].AsInteger := 1;
  end;
  Button2.Enabled := True;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if NextGrid1.RowExist(NextGrid1.SelectedRow) then
    NextGrid1.DeleteRow(NextGrid1.SelectedRow);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if NextGrid1.RowExist(NextGrid1.SelectedRow) then
    NextGrid1.ClearChildRows(NextGrid1.SelectedRow);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  ShowMessage(IntToStr(NextGrid1.GetChildCount(NextGrid1.SelectedRow)));
end;

procedure TForm1.Button6Click(Sender: TObject);
var
  Pos: Integer;
begin
  Pos := NextGrid1.GetNextSibling(NextGrid1.SelectedRow);
  if NextGrid1.RowExist(Pos) then NextGrid1.SelectedRow := Pos;
end;

procedure TForm1.Button7Click(Sender: TObject);
var
  Pos: Integer;
begin
  Pos := NextGrid1.GetPrevSibling(NextGrid1.SelectedRow);
  if NextGrid1.RowExist(Pos) then NextGrid1.SelectedRow := Pos;
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
begin
  NxTreeColumn1.ShowLines := (Sender as TCheckBox).Checked;
end;

procedure TForm1.CheckBox4Click(Sender: TObject);
begin
  if TCheckBox(Sender).Checked then
  begin
    NxTreeColumn1.Options := NxTreeColumn1.Options + [coEditing];
  end else NxTreeColumn1.Options := NxTreeColumn1.Options - [coEditing];
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  NextGrid1.SelectedRow := NextGrid1.GetLastChild(NextGrid1.SelectedRow);
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  NextGrid1.SelectedRow := NextGrid1.GetFirstChild(NextGrid1.SelectedRow);
end;

end.
