unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, NxScrollControl, NxCustomGridControl, NxCustomGrid, NxDBGrid,
  DBTables, DB, NxColumns, NxDBColumns, StdCtrls, ExtCtrls, DBCtrls;

type
  TForm1 = class(TForm)
    NextDBGrid1: TNextDBGrid;
    Table1: TTable;
    Query1: TQuery;
    DataSource1: TDataSource;
    NxDBTextColumn1: TNxDBTextColumn;
    Table2: TTable;
    NxDBTextColumn2: TNxDBTextColumn;
    NxLookupColumn1: TNxLookupColumn;
    DataSource2: TDataSource;
    Label1: TLabel;
    Button1: TButton;
    NxDBIncrementColumn1: TNxDBIncrementColumn;
    CheckBox1: TCheckBox;
    NxDBNumberColumn1: TNxDBNumberColumn;
    Button3: TButton;
    ListBox1: TListBox;
    Button4: TButton;
    Button2: TButton;
    DBNavigator1: TDBNavigator;
    Button5: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure NextDBGrid1ChangeRowHeight(Sender: TObject; Index,
      Height: Integer);
    procedure NextDBGrid1MeasuringRowHeight(Sender: TObject;
      Index: Integer; var RowHeight: Integer);
    procedure NextDBGrid1SelectCell(Sender: TObject; ACol, ARow: Integer);
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure NextDBGrid1FooterClick(Sender: TObject; ACol: Integer);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure NextDBGrid1CellColoring(Sender: TObject; ACol, ARow: Integer;
      var CellColor, GridColor: TColor; CellState: TCellState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TRowSize = class
    Index: Integer;
    Value: Integer;
  end;

var
  Form1: TForm1;
  RowHeightList: TList;

implementation

{$R *.dfm}

function GetSize(Index: Integer): Integer;
var
  I: Integer;
  ARowSize: TRowSize;
begin
  Result := 16;
  for I := 0 to RowHeightList.Count - 1 do
  begin
    ARowSize := TRowSize(RowHeightList.Items[I]);
    if ARowSize.Index = Index then
    begin
      Result := ARowSize.Value;
      Exit;
    end;
  end;
end;

procedure SetSize(Index, Value: Integer);
var
  I: Integer;
  ARowSize: TRowSize;
  Done: Boolean;
begin
  Done := False;
  for I := 0 to RowHeightList.Count - 1 do
  begin
    ARowSize := TRowSize(RowHeightList.Items[I]);
    if ARowSize.Index = Index then
    begin
      ARowSize.Value := Value;
      Exit;
    end;
  end;
  if not Done then
  begin
    ARowSize := TRowSize.Create;
    ARowSize.Index := Index;
    ARowSize.Value := Value;
    RowHeightList.Add(ARowSize);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  C: HCURSOR;
begin
  RowHeightList := TList.Create;

  C := LoadCursor(0, IDC_HAND);
  if C <> 0 then Screen.Cursors[crHandPoint] := C;
  Table1.Close;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  RowHeightList.Free;
end;

procedure TForm1.NextDBGrid1ChangeRowHeight(Sender: TObject; Index,
  Height: Integer);
begin
  if RowHeightList <> nil then
  begin
    SetSize(Index, Height);
    NextDBGrid1.Invalidate;
  end;
end;

procedure TForm1.NextDBGrid1MeasuringRowHeight(Sender: TObject;
  Index: Integer; var RowHeight: Integer);
begin
  if RowHeightList <> nil then RowHeight := GetSize(Index);
end;

procedure TForm1.NextDBGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer);
begin
  Label1.Caption := 'Select Count:' + IntToStr(NextDBGrid1.SelectedCount);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  NextDBGrid1.Selected[3] := True;
  NextDBGrid1.Selected[7] := True;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if TCheckBox(Sender).Checked then
    NextDBGrid1.DataAwareOptions := NextDBGrid1.DataAwareOptions + [doBufferRecords]
  else
    NextDBGrid1.DataAwareOptions := NextDBGrid1.DataAwareOptions - [doBufferRecords];
end;

procedure TForm1.NextDBGrid1FooterClick(Sender: TObject; ACol: Integer);
begin
  NextDBGrid1.CalculateFooter;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Table1.Close;
  Table1.DatabaseName := ExtractFilePath(ParamStr(0)) + '..\data';
  Table1.TableName := 'employee';
  Table1.Open;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  i: Integer;
begin
  ListBox1.Clear;
  for i := 0 to NextDBGrid1.RowCount - 1 do
  begin
    if NextDBGrid1.Selected[i] then
      ListBox1.Items.Add(NextDBGrid1.Cells[1, i] + ', ' + NextDBGrid1.Cells[2, i]);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  NextDBGrid1.SelectLastRow;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
Table1.Filter := 'Salary > 30000';
Table1.Filtered := True;
Table1.Refresh;
NextDBGrid1.VertScrollBar.First;
end;

procedure TForm1.NextDBGrid1CellColoring(Sender: TObject; ACol,
  ARow: Integer; var CellColor, GridColor: TColor; CellState: TCellState);
begin
  if csSelected in CellState then CellColor := clRed;
end;

end.
