unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    MasterTable: TADOTable;
    DetailTable: TADOTable;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    NextDBGrid1: TNextDBGrid;
    Panel2: TPanel;
    DBGridView2: TNextDBGrid;
    Splitter1: TSplitter;
    NxDBNumberColumn1: TNxDBNumberColumn;
    NxDBTextColumn1: TNxDBTextColumn;
    NxDBTextColumn2: TNxDBTextColumn;
    NxDBTextColumn3: TNxDBTextColumn;
    NxDBTextColumn4: TNxDBTextColumn;
    NxDBTextColumn5: TNxDBTextColumn;
    NxDBTextColumn6: TNxDBTextColumn;
    NxDBNumberColumn2: TNxDBNumberColumn;
    NxDBNumberColumn3: TNxDBNumberColumn;
    NxDBTextColumn7: TNxDBTextColumn;
    NxDBNumberColumn4: TNxDBNumberColumn;
    procedure FormCreate(Sender: TObject);
    procedure DBGridView2SlideColoring(Sender: TObject; Index: Integer;
      var SlideColor, GridColor: TColor; SlideState: TSlideState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function GetCellTextSize(N: TNextDBGrid; ACol, ARow: Integer): TSize;
const
  Params: TDrawTextParams =(Cbsize: 20; iTabLength: 0; iLeftMargin: 2; iRightMargin: 8; uiLengthDrawn: 0);
var
  r: TRect;
  ws: widestring;
begin
  ws := N.Cells[ACol, ARow];
  r := N.GetCellRect(ACol, ARow);

  if (N.Columns[ACol].WrapKind = wkWordWrap) then
  Result.cy := DrawTextExW(N.Canvas.Handle, PWidechar(ws), Length(ws), r, DT_LEFT or DT_WORDBREAK or DT_NOPREFIX or DT_CALCRECT, @params) + 6
  else
  Result.cy := DrawTextExW(N.Canvas.Handle, PWidechar(ws), Length(ws), r, DT_LEFT or DT_SINGLELINE or DT_NOPREFIX or DT_CALCRECT, @params) + 6;

  if Result.cy < N.RowSize then
  Result.cy := N.RowSize;

  Result.cx := r.Right - r.Left;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  SourceStr: string;
begin
  SourceStr := ExtractFilePath(ParamStr(0)) + '..\Data\dbdemos.mdb';
  ADOConnection1.Close;
  ADOConnection1.ConnectionString :=	'Provider=Microsoft.Jet.OLEDB.4.0;' +
  																		'User ID=Admin;' +
                                      'Data Source=' + SourceStr + ';' +
                                      'Mode=ReadWrite;Extended Properties="";' +
                                      'Jet OLEDB:System database="";' +
                                      'Jet OLEDB:Registry Path="";' +
                                      'Jet OLEDB:Database Password="";' +
                                      'Jet OLEDB:Engine Type=5;' +
                                      'Jet OLEDB:Database Locking Mode=1;' +
                                      'Jet OLEDB:Global Partial Bulk Ops=2;' +
                                      'Jet OLEDB:Global Bulk Transactions=1;' +
                                      'Jet OLEDB:New Database Password="";' +
                                      'Jet OLEDB:Create System Database=False;' +
                                      'Jet OLEDB:Encrypt Database=False;' +
                                      'Jet OLEDB:Don' + Char(39) + 't Copy Locale on Compact=False;' +
                                      'Jet OLEDB:Compact Without Replica Repair=False;' +
                                      'Jet OLEDB:SFP=False';
  ADOConnection1.Open;
  MasterTable.Close;
  DetailTable.Close;
  MasterTable.Open;
  DetailTable.Open;
end;

procedure TForm1.DBGridView2SlideColoring(Sender: TObject; Index: Integer;
  var SlideColor, GridColor: TColor; SlideState: TSlideState);
begin
  SlideColor := DBGridView2.Color;

  if DataSource2.DataSet.FieldByName('OrderId').AsInteger <= 19 then
    SlideColor := clRed;

  if DataSource2.DataSet.FieldByName('OrderId').AsInteger = 20 then
    SlideColor := clYellow;

  if DataSource2.DataSet.FieldByName('OrderId').AsInteger >= 21 then
    SlideColor := clGreen;
end;

end.
