Documents

NextGrid & NextDBGrid

NextGrid

NextDBGrid

NextInspector

NextSheet

NextCollection

Misc

Labs

NextGrid .NET

NextDBGrid Quick Start

Related Articles:

Info
  • Skill:
  • Version: 1.0.1
  • Author: Bojan Nikolic
  • Created: 2008-04-22
  • Updated: 2008-05-30
NextDBGrid and NextGrid are derived from same ancestor class TNxCustomGrid and share most of all methods and properties. Working with columns and design-time editor is same in both component.

1. How NextDBGrid work



NextDBGrid unlike NextGrid doesn't store data within own memory space. Instead it load data fields directly from DataSet and display it in column-type presentation. Each Column withing NextDBGrid may represent one TField and on column type depends how this field will be drawn (as text, progress bar, checkbox...).

When start drawing, NextDBGrid point ActiveRecord to the first visible record on screen. Then draw each cell in this row. Since ActiveRow is set Field property of DataSet or column may be used. After 1st row is drawn ActiveRecord is moved down and now Field objects are re-loaded with data from 2nd record.



As every column have property Field attached to a Field from DataSet, we may easily inspect this property on every drawing events such as OnCellColoring, OnCustomDrawCell...

Example:

procedure TForm1.NextDBGrid1CellColoring(Sender: TObject; ACol,
  ARow: Integer; var CellColor, GridColor: TColor; CellState: TCellState);
var Field: TField;
begin
  Field := NextDBGrid1.Columns[ACol].Field;
  if Assigned(Field) and (Field.AsInteger = 0) then
  begin
    CellColor := clRed;
  end;
end;


2. Design-time quick start



Working with NextDBGrid in design-time mode is allmost same as working with NextGrid. Only difference is in new properties after clicking on either grid or column.

In most cases grid is first goin to be connected to DataSource.



Then FieldName property need to be set for desired columns.



If DataSet (TTable, TADOTable, TQuery...) is active, column will display data automatically.

3. New properties for NextDBGrid



DataAwareOptions property consist from set of flags which specify how grid will act with db-related options:

Table 1: DataAwareOptions Flags
Name Meaning
doAddColumns If DataSource property is set, and DataSet new column will be added for each field if this flag is set.
doAddIncrementColumn Automatically add TNxDbIncrementColumn. This may be very useful when columns are added on DataSet activation.
doAutoAssignFieldName This flag is usefull when DataSet is not active, but we have configure columns in design-time. After DataSet become active, each column will "grab" first next Field and so on.
doBufferRecords When this flag is not set, only records visible on screen will be downloaded (similar to Delphi's DBGrid). When set to True all records will be downloaded into internal buffer which may take a time to load and consumes more memory. But also, grid act more like standard non-db grid.
doClearColumnsOnDeactivate Delete all columns on DataSet deactivate only if doAutoDelete is set in DataAwareOptions of Column.
doRetreiveRecords Scroll DataSet to the last record to downloa all records.
doSetColumnWidth When columns are automatically added on DataSet activate Column's Width to be same as Field.DisplayWidth.


3.1. DataSource property



As any other Db-related control NextDBGrid also have DataSource property. It is used as usuall with any db-related control. If DataSource is already connected to the active DataSet (TTable, TQuery...), column will be automatically added into NextDBGrid for each field from DataSet.

Beside this 2 properties at the moment there are no new properties for NextDBGrid from NextGrid. Columns introduce new properties too.

4. DB Columns



Main descendant for db columns is TNxDBCustomColumn. Every db-column type is derrived from this class. This class introduce several important properties after it's ancestor TNxCustomControl.



Name Type Meaning
Field TField Field associated to the column. Column draw it's content and apply editing into it.
FieldName string Specify name of Field to be associated to the column. If field with this name exist, Field property will be set.
DataAwareOptions TColumnDataAwareOptions Specify Data-aware options for column. Will be described bellow.
NullText WideString Specify text which will be displayed when content of associated Field is NULL


DataAwareOptions property specify db-related options for column.

Name Meaning
daAutoAssign If this property is set to True and doAutoAssignFieldName glag in Options property of grid is set, column will auto-assign field name after DataSet activate.
daAutoDelete If this option is set to True and doClearColumnsOnDeactivate flag in Options property of grid is set, column will be deleted on DataSet deactivate.
daLinkField If this option is set to True column will retreive important informations from Field. Example: For TNxDBNumberColumn Max and Min properties are loaded from MaxValue and MinValue of TFloatField

Was This Article Useful?

Only constructive comments, code contributions... will be publishes. Questions, non-official discussion will not be published.