unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    NextGrid1: TNextGrid;
    Button1: TButton;
    edtRowCount: TNxSpinEdit;
    NxTextColumn1: TNxTextColumn;
    NxTextColumn3: TNxTextColumn;
    NxImageColumn1: TNxImageColumn;
    NxNumberColumn1: TNxNumberColumn;
    Label1: TLabel;
    NxSpinEdit2: TNxSpinEdit;
    NxProgressColumn1: TNxProgressColumn;
    NxCheckBoxColumn1: TNxCheckBoxColumn;
    edtHeaderSize: TNxSpinEdit;
    Label2: TLabel;
    CheckBox1: TCheckBox;
    imlEmails: TImageList;
    NxComboBoxColumn1: TNxListColumn;
    procedure NxSpinEdit2Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure edtHeaderSizeChange(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure NextGrid1CellFormating(Sender: TObject; ACol, ARow: Integer;
      var TextColor: TColor; var FontStyle: TFontStyles;
      CellState: TCellState);
    procedure NextGrid1FooterClick(Sender: TObject; ACol: Integer);
  private
    { Private declarations }
  public
    procedure AddRow(RowCount: Integer);
  end;

var
  Form1: TForm1;
  Names: array[0..9] of string = (
    'Mike', 'Jim', 'Lisa', 'Mary', 'Jonathan', 'Michael', 'Lora', 'Caren', 'Kim', 'George'
  );


implementation

uses Math;

{$R *.dfm}

procedure TForm1.AddRow(RowCount: Integer);
var
  i: Integer;
begin
  Randomize;
  NextGrid1.AddRow(RowCount);
  with NextGrid1 do
  begin
    for i := NextGrid1.RowCount - RowCount to NextGrid1.RowCount - 1 do
    begin
      Cell[0, i].AsInteger := Random(2);
      Cell[2, i].AsString := Names[Random(Length(Names))];
      Cell[3, i].AsString := Names[Random(Length(Names))];
      Cell[4, i].AsInteger := Random(50000);
      Cell[5, i].AsInteger := Random(3);
      Cell[6, i].AsInteger := Random(100);
    end;
  end;
end;

procedure TForm1.NxSpinEdit2Change(Sender: TObject);
begin
  with Sender as TNxSpinEdit do
  begin
    if InRange(AsInteger, 0, NextGrid1.Columns.Count - 1) then
    begin
      NextGrid1.FixedCols := AsInteger;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  AddRow(edtRowCount.AsInteger);
end;

procedure TForm1.edtHeaderSizeChange(Sender: TObject);
begin
  NextGrid1.HeaderSize := edtHeaderSize.AsInteger;
end;

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

procedure TForm1.NextGrid1CellFormating(Sender: TObject; ACol,
  ARow: Integer; var TextColor: TColor; var FontStyle: TFontStyles;
  CellState: TCellState);
begin
  if csSelected in CellState then Exit;
  if (ACol = 4) and (NextGrid1.Cell[ACol, ARow].AsFloat < 10000) then
  begin
    TextColor := clRed;
  end;
end;

procedure TForm1.NextGrid1FooterClick(Sender: TObject; ACol: Integer);
begin
  NextGrid1.CalculateFooter;
end;

end.
