unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    NextGrid1: TNextGrid;
    NxCheckBoxColumn1: TNxCheckBoxColumn;
    Button1: TButton;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    NxTextColumn1: TNxTextColumn;
    NxTextColumn2: TNxTextColumn;
    NxSpinEdit1: TNxSpinEdit;
    NxNumberColumn1: TNxNumberColumn;
    NxImageColumn1: TNxImageColumn;
    ImageList1: TImageList;
    NxIncrementColumn1: TNxIncrementColumn;
    NxProgressColumn1: TNxProgressColumn;
    NxTextColumn3: TNxTextColumn;
    NxDateColumn1: TNxDateColumn;
    Button2: TButton;
    NxComboBox1: TNxComboBox;
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure NextGrid1SelectCell(Sender: TObject; ACol, ARow: Integer);
    procedure CheckBox2Click(Sender: TObject);
    procedure NxSpinEdit1Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure NxComboBox1Select(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Names: array[0..9] of string = ('Jack', 'Lisa', 'Marry', 'Robert', 'Mike',
    'Ben', 'Donald', 'Barry', 'Freddy', 'Harry');
  Cities: array[0..9] of string = ('New York', 'Los Angeles', 'San Francisco', 'Miami',
    'Denver', 'Washington', 'Baltimore', 'Sacramento', 'Las Vegas', 'New Jersey');
  Clicked: Boolean = False;

implementation

uses Math;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  NextGrid1.AddRow;
  with NextGrid1 do
  begin
    Cell[3, LastAddedRow].AsString := Names[Random(9)];
    Cell[4, LastAddedRow].AsString := Names[Random(9)];
    Cell[5, LastAddedRow].AsInteger := Random(10000) + 10000;
    Cell[6, LastAddedRow].AsInteger := Random(100);
    Cell[7, LastAddedRow].AsString := Cities[Random(9)];
    Cell[8, LastAddedRow].AsDateTime := Today - Random(4);
  end;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  case (Sender as TCheckBox).Checked of
    True: NextGrid1.Options := NextGrid1.Options + [goIndicator];
    else NextGrid1.Options := NextGrid1.Options - [goIndicator];
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  Randomize;
  NxSpinEdit1.Max := NextGrid1.Columns.Count;

  NxComboBox1.Items.Add('<Scroll To>');
  for i := 0 to NextGrid1.Columns.Count - 1 do
    NxComboBox1.Items.Add(IntToStr(i) + ': ' + NextGrid1.Columns[i].Header.Caption);
  NxComboBox1.ItemIndex := 0;
end;

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

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  case (Sender as TCheckBox).Checked of
    True: NextGrid1.Options := NextGrid1.Options + [goLockFixedCols];
    else NextGrid1.Options := NextGrid1.Options - [goLockFixedCols];
  end;
end;

procedure TForm1.NxSpinEdit1Change(Sender: TObject);
begin
  NextGrid1.FixedCols := NxSpinEdit1.AsInteger;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to NextGrid1.Columns.Count - 1 do
  begin
    NextGrid1.Columns[i].Visible := True;
  end;
end;

procedure TForm1.NxComboBox1Select(Sender: TObject);
var
  Col: Integer;
begin
  Col := NxComboBox1.ItemIndex - 1;
  if InRange(Col, 0, NextGrid1.Columns.Count - 1) then
    NextGrid1.ScrollToColumn(NextGrid1.Columns[Col]);
end;

end.
