unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, NxVirtualDataSet, NxColumns, NxColumnClasses, NxDBGrid,
  NxScrollControl, NxCustomGridControl, NxCustomGrid, NxGrid, StdCtrls,
  NxDBColumns;

type
  TForm1 = class(TForm)
    NextGrid1: TNextGrid;
    NextDBGrid1: TNextDBGrid;
    NxTextColumn1: TNxTextColumn;
    NxVirtualDataSet1: TNxVirtualDataSet;
    Button1: TButton;
    DataSource1: TDataSource;
    NxDBCheckBoxColumn1: TNxDBCheckBoxColumn;
    NxDBTextColumn1: TNxDBTextColumn;
    NxCheckBoxColumn1: TNxCheckBoxColumn;
    Button2: TButton;
    NxListColumn1: TNxListColumn;
    NxDBListColumn1: TNxDBListColumn;
    function NxVirtualDataSet1RecordCount(Sender: TObject): Integer;
    function NxVirtualDataSet1FieldCount(Sender: TObject): Integer;
    procedure Button1Click(Sender: TObject);
    function NxVirtualDataSet1GetFieldData(Sender: TObject; const rowIndex,
      fieldIndex: Integer): OleVariant;
    procedure FormCreate(Sender: TObject);
    procedure NxVirtualDataSet1AddField(Sender: TObject;
      const fieldIndex: Integer; var fieldName: String;
      var fieldSize: Integer; var DataType: TFieldType);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses NxCells;

{$R *.dfm}

function TForm1.NxVirtualDataSet1RecordCount(Sender: TObject): Integer;
begin
  Result := NextGrid1.RowCount;
end;

function TForm1.NxVirtualDataSet1FieldCount(Sender: TObject): Integer;
begin
  { We have 3 Fields }
  Result := 3;
end;

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

function TForm1.NxVirtualDataSet1GetFieldData(Sender: TObject;
  const rowIndex, fieldIndex: Integer): OleVariant;
begin
  case fieldIndex of
    0: Result := NextGrid1.Cell[fieldIndex, rowIndex].AsBoolean; { checked/unchecked }
    1: Result := NextGrid1.Cell[fieldIndex, rowIndex].AsInteger; { ItemIndex }
    2: Result := NextGrid1.Cell[fieldIndex, rowIndex].AsString;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  NxVirtualDataSet1.Open;
end;

procedure TForm1.NxVirtualDataSet1AddField(Sender: TObject;
  const fieldIndex: Integer; var fieldName: String; var fieldSize: Integer;
  var DataType: TFieldType);
begin
  case fieldIndex of
    0:
    begin
      fieldName := 'Checked';
      DataType := ftBoolean;
      fieldSize := 1;
    end;
    1:
    begin
      fieldName := 'Priority';
      DataType := ftSmallint;
      fieldSize := 3; { Low/Normal/High }
    end;
    2:
    begin
      fieldName := 'Name';
      DataType := ftString;
      fieldSize := 24;
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  NxVirtualDataSet1.Refresh;
end;

end.
