unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    NextDBGrid1: TNextDBGrid;
    Table1: TTable;
    DataSource1: TDataSource;
    NxDBTextColumn1: TNxDBTextColumn;
    NxDBTextColumn2: TNxDBTextColumn;
    NxDBIncrementColumn1: TNxDBIncrementColumn;
    CheckBox1: TCheckBox;
    NxDBNumberColumn1: TNxDBNumberColumn;
    Button3: TButton;
    NxLookupColumn1: TNxLookupColumn;
    Table2: TTable;
    DataSource2: TDataSource;
    NxDBRateColumn1: TNxDBRateColumn;
    Button1: TButton;
    DBNavigator1: TDBNavigator;
    Button2: 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 CheckBox1Click(Sender: TObject);
    procedure NextDBGrid1FooterClick(Sender: TObject; ACol: Integer);
    procedure Button3Click(Sender: TObject);
    procedure NxVirtualColumn1GetText(Sender: TObject; const ACol,
      ARow: Integer; var Value: WideString);
    procedure NxVirtualColumn1SetText(Sender: TObject; const ACol,
      ARow: Integer; const Value: WideString);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public

  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.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
  if ACol = 3 then
    NextDBGrid1.CalculateFooter;
end;

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

  Table2.Close;
  Table2.DatabaseName := ExtractFilePath(ParamStr(0)) + '..\data';
  Table2.TableName := 'jobs';
  Table2.Open;
  NextDBGrid1.CalculateFooter;
end;

procedure TForm1.NxVirtualColumn1GetText(Sender: TObject; const ACol,
  ARow: Integer; var Value: WideString);
var
  Tax: Double;
begin
  Tax := NextDBGrid1.Columns[3].Field.AsFloat * 0.2;
  Value := FloatToStr(Tax);
end;

procedure TForm1.NxVirtualColumn1SetText(Sender: TObject; const ACol,
  ARow: Integer; const Value: WideString);
begin
  MessageDlg('Value is set to VirtualColumn: ' + Value, mtInformation, [mbOk], 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  NextDBGrid1.ScrollToRow(20);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  NextDBGrid1.DataAwareOptions := NextDBGrid1.DataAwareOptions + [doImmediatePost];
end;

end.
