Documents

NextGrid & NextDBGrid

NextGrid

NextDBGrid

NextInspector

NextSheet

NextCollection

Misc

Labs

NextGrid .NET

NextDBGrid Events

Related Articles:

Info
  • Skill:
  • Version: 1.0.1
  • Author: Bojan Nikolic
  • Created:
  • Updated: 2008-04-22

OnApplyCell



This event occur when conten't value are goin to be drawn. Value is first reaeded from TField and then drawn. Between this 2 process OnApplyCell event occur and we may set that other value is drawn than one from TField.

Table 1: OnColumnAdded Parameters
Name Type Meaning
ACol Integer Indicate Column Index of currently drawing cell.
ARow Integer Indicate Row Index of currently drawing cell.
Value WideString Determine or specify cell's drawing value.


Usual scenario for using this event is reading Value parameter and adjust it additionally.

Another way may be using Field property (TField) of currently drawing column access to it and adjust Value parameter.

procedure TForm1.NextDBGrid1ApplyCell(Sender: TObject; ACol, ARow: Integer;
  var Value: WideString);
var
  Field: TField;
begin
  Field := NextDBGrid1.Columns[ACol].Field;
  if Field <> nil then
  begin
    if Field.AsString = '' then Value := '';
  end;
end;


OnColumnCreate



This event occur when DataSet is activated and columns are added (doAddColumns flag must be True in DataAwareOptions). This is Point where class of newly added Column can be changed. Also adding column can be canceled.

Parameters:

Table 2: OnColumnCreate Parameters
Name Type Meaning
Field TField Indicate TField in progress. When DataSet is activated, Next DBGrid add one column and occur this event for each TField in DataSet.
ColumnClass TNxDBColumnClass Column class of newly added Column. Using this parameter, column type can be changed.
AddColumn Boolean Default is True. When is set to False, column will NOT be added.


As this event occur for each TField from DataSet when is activated, we may decide which field will have own column with grid, or change type of column. For example if default column are goin to be added TNxDBNumberColumn we may set ColumnClass property to be TNxDBImageColumn instead.

procedure TForm1.NextDBGrid1ColumnCreate(Sender: TObject; Field: TField;
  var ColumnClass: TNxColumnClass; var AddColumn: Boolean); 
begin
  if Field.FieldName = 'Progress' then ColumnClass := TNxDBProgressColumn;
  if Field.IsBlob then AddColumn = False; // Don't add column for BLOB fields
end;


If AddColumn = True, [/code]OnColumnAdded[/code] event will occur next for this columns.

OnColumnAdded



This event occur when new Column is added after DataSet is activated. This is Point where new Column may be additionaly customized.

Parameters:

Table 3: OnColumnAdded Parameters
Name Type Meaning
Column TNxDBCustomColumn Indicate newly added column.


procedure TForm1.NextDBGrid1ColumnAdded(Sender: TObject;
  Column: TNxDBCustomColumn);
begin
  if Column is TNxDBCheckBoxColumn then
  begin
    with Column as TNxDBCheckBoxColumn do
    begin
      Alignment := taCenter;
      ValueChecked := 'True';
      ValueUnchecked := 'False';
      Width := 50;
    end;
  end;
end;


In this example we have customize newly added CheckBox Column.

OnMeasuringRowHeight



This event occur in Cells drawing process, when Grid need to acquire Row Height. Default Value for each row is equal to property RowSize, but with using this event Row Height can be additionaly adjusted.

Table 4: OnMeasuringRowHeight Parameters
Name Type Meaning
Index Integer Indicate Index of Row being drawn.
RowHeight Integer Gets or Sets Row Height of current Row.


procedure TForm1.NextDBGrid1MeasuringRowHeight(Sender: TObject;
  Index: Integer; var RowHeight: Integer);
begin
  if Index = 5 then RowHeight := 45;
end;

Was This Article Useful?

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