Documents

NextGrid & NextDBGrid

NextGrid

NextDBGrid

NextInspector

NextSheet

NextCollection

Misc

Labs

NextGrid .NET

NextDBGrid How To

Related Articles:

Info
  • Skill:
  • Version: 1.0.0
  • Author: Bojan Nikolic
  • Created: 2009-07-25
  • Updated: 2009-08-26

Content:


1. Using OnApplyCell event
2. Display Cell Hint
3. Display content of Memo Field
4. Get content from DataSet outside Grid's buffered records scope


1. Using OnApplyCell event



While cell is rendered on screen, NextDBGrid read Field's value associated with FieldName property.

With using OnApplyCell event, cell value may be additionally adjusted.

In this example value (AsFloat) from Field property of 1st column is read and parameter Value is set for 2nd column (ACol = 1).

procedure TForm1.NextDBGrid1ApplyCell(Sender: TObject; ACol, ARow: Integer;
  var Value: WideString);
begin
  if ACol = 1 then
  begin
    if NextDBGrid1.Columns[0].Field.AsFloat > 10000 then
    begin
      Value := '2';
    end else
    if NextDBGrid1.Columns[0].Field.AsFloat < 10000 then
    begin
      Value := '1';
    end else Value := '0';
  end;
end;


2. Display Cell Hint



With using OnCellHint event custom hint message may be displayed when user move mouse over cell.

procedure TForm1.NextDBGrid1CellHint(Sender: TObject; ACol, ARow: Integer;
  var Value: WideString);
var
  Field: TField;
begin
  if ACol = 1 then
  begin
    Field := NextDBGrid1.Columns[0].Field;
    Value := 'OnCellHint'   #13#10   'This cell have own hint from OnCellHint event.';
  end;
end;


3. Display content of Memo Field



By default MemoField display Memo Field as "(MEMO)" string. NxDBMemoColumn having possibility to display Memo Fields in full.

Table 1. MemoDisplayOptios property
Name Meaning
mdDefault Display Memo Field as (MEMO) string
mdContent Display full content of Memo Field


4. Get content from DataSet outside Grid's buffered records scope



function TForm1.GetFieldValue(DataSet: TDataSet; ACol, ARow: Integer): WideString;
var
  B: TBookmark;
begin
  DataSet.DisableControls;
  B := DataSet.GetBookmark;
  DataSet.First;
  DataSet.MoveBy(ARow);
  Result := DataSet.Fields[ACol].AsString;
  DataSet.GotoBookmark(B);
  DataSet.EnableControls;
end;


To fill list with selected rows from grid, use next code:

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  ListBox1.Clear;
  for i := 0 to NextDBGrid1.RowCount - 1 do
  begin
    if NextDBGrid1.Selected[i] then
      ListBox1.Items.Add(GetFieldValue(ADOTable1, 1, i));
  end;
end;

Was This Article Useful?

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