unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.StdCtrls, NxGrid6,
  NxGridView6, NxColumns6, NxControls6, NxCustomGrid6, NxVirtualGrid6, NxDBGrid6,
  NxDBColumns6, NxTypes6, Vcl.ExtCtrls, Vcl.DBCtrls, Vcl.Mask, NxEdit6;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    NextDBGrid61: TNextDBGrid6;
    NxReportGridView61: TNxReportGridView6;
    Button1: TButton;
    CheckBox1: TCheckBox;
    DataSource1: TDataSource;
    CheckBox2: TCheckBox;
    DBNavigator1: TDBNavigator;
    Button2: TButton;
    Button3: TButton;
    DBEdit1: TDBEdit;
    Label1: TLabel;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    ColorDialog1: TColorDialog;
    Button4: TButton;
    CheckBox3: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure NextDBGrid61AddFieldQuery(Sender: TObject; Field: TField;
      var ColumnClass: TNxColumnClass; var Accept: Boolean);
    procedure NextDBGrid61FieldAdded(Sender: TObject; Field: TField;
      Column: TNxColumn6);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
  private
    procedure ColorColumnDrawContent(Sender: TObject; ACol, ARow: Integer;
      CellRect: TRect; State: TNxCellPaintingState);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  NextDBGrid61.AddCells(['New Project'],
    [1]);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  NextDBGrid61.SelectedCell.AsString := 'Sample';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  ADOTable1.Locate('Project', 'Project 12', [loCaseInsensitive]);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  Dialog: TColorDialog;
begin
  Dialog := TColorDialog.Create(Self);
  Dialog.Color := DataSource1.DataSet.FieldByName('Color').AsInteger;
  if Dialog.Execute then
  begin
    DataSource1.DataSet.Edit;
    DataSource1.DataSet.FieldByName('Color').AsInteger := Dialog.Color;
    DataSource1.DataSet.Post;
  end;
  Dialog.Free;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  ADOTable1.Active := TCheckBox(Sender).Checked;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  NextDBGrid61.BufferRecords := TCheckBox(Sender).Checked;
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
begin
  NextDBGrid61.MultiSelect := TCheckBox(Sender).Checked;
  NextDBGrid61.SelectFullRow := TCheckBox(Sender).Checked;
end;

procedure TForm1.ColorColumnDrawContent(Sender: TObject; ACol, ARow: Integer;
  CellRect: TRect; State: TNxCellPaintingState);
begin
  with NextDBGrid61.Canvas do
  begin
    InflateRect(CellRect, -4, -2);
    Pen.Color := clGrayText;
    Brush.Color := NextDBGrid61.Cell[ACol, ARow].AsInteger;
    Rectangle(CellRect);
  end;
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;
  DBEdit1.DataField := 'Project';
  DBEdit2.DataField := 'Cost';
end;

procedure TForm1.NextDBGrid61AddFieldQuery(Sender: TObject; Field: TField;
  var ColumnClass: TNxColumnClass; var Accept: Boolean);
begin
  if Field.FieldName = 'Progress' then
  begin
    Field.DisplayLabel := 'Track';
    ColumnClass := TNxDBTrackbarColumn6;
  end;
  if Field.FieldName = 'Color' then
  begin
    ColumnClass := TNxDBTextColumn6;
  end;
end;

procedure TForm1.NextDBGrid61FieldAdded(Sender: TObject; Field: TField;
  Column: TNxColumn6);
begin
  if Field.FieldName = 'Active' then
    with Column as TNxDBCheckBoxColumn6 do
    begin
      Alignment := TAlignment.taCenter;
    end;

  if Field.FieldName = 'Project' then
    with Column as TNxDBTextColumn6 do
    begin
    end;

  if Field.FieldName = 'Progress' then
    with Column as TNxDBTrackbarColumn6 do
    begin
      Interactive := True;
      ShowText := False;
    end;
  if Field.FieldName = 'Color' then
    with Column as TNxDBTextColumn6 do
    begin
      Editing := False;
      DrawingOptions := [doBackground, doCustom];
      OnDrawContent := ColorColumnDrawContent;
      Width := 40;
      ShowTextFitHint := False;
      Position := 1;
    end;
  if Field.FieldName = 'ID' then
    with Column as TNxDBNumberColumn6 do
    begin
      Precision := 0;
    end;
end;

end.
