OnBeforeDrawCell

Class: TEgFireGrid

property OnBeforeDrawCell: TEgFireGridBeforeDrawCellEvent;

TEgFireGridBeforeDrawCellEvent = procedure(Sender: TObject; Column: TEgFireGridColumn; RowIndex: Integer;
  Cell: TEgFireGridCellControl; var Text: string) of object;

Occurs for each data cell when the grid fills it with the data of its row, before it is shown. The handler can change, for that cell only, what the cell shows:

What How
The text Assign Text. It may contain <var>Name</var> and <br> markers (not in a memo column), resolved after the handler.
The background colour Assign Cell.BackColor (TAlphaColors.Null = none).
The text colour Assign Cell.CellFontColor.
The font style Assign Cell.CellFontStyle, for example [TFontStyle.fsBold].
The icon Assign Cell.ImageIndex (-1 = none) and Cell.ImageAlignment.

Every one of them arrives as the column resolves it: Text is the field’s display text (with the field’s DisplayFormat, or the column’s DisplayFormat when assigned; a memo’s text trimmed and cut at MemoMaxChars), BackColor is the column’s Color, the icon is the column’s ImageIndex. A value left untouched keeps the column’s look. Every time the cell is filled, all of them start again from the column’s values, so a handler only changes the cells that differ: a cell whose row no longer meets the condition goes back to the column’s look by itself.

Column is the cell’s column and RowIndex its window row (0 = the first row shown). The dataset’s active record is not moved to that row: read another field of the same row with RowSource.GetValue(RowIndex, FieldName). A column with no FieldName has an empty Text, which the handler can fill, for example with a value computed from the other fields of the row.

The grid’s handler runs first, then the column’s own OnBeforeDrawCell, which receives Text as the grid’s handler left it.

The event fires whenever the cells are filled again: when the grid scrolls, when the data or the columns change, when the grid is resized; not at every repaint. It must be quick, and it must not move the dataset, change the columns or the grid’s properties. Do not change the cell’s own Font or FontColor: they are set from the column after the event; use CellFontColor and CellFontStyle.

In a check box column the text is not shown, and in a picture column the text is shown only when the field’s bytes are not a picture.

Example

Negative prices in bold red on a light red background:

procedure TForm1.Grid1BeforeDrawCell(Sender: TObject; Column: TEgFireGridColumn; RowIndex: Integer;
  Cell: TEgFireGridCellControl; var Text: string);
var
  Price: Variant;
begin
  if SameText(Column.FieldName, 'Price') then
  begin
    Price := Grid1.RowSource.GetValue(RowIndex, 'Price');
    if not VarIsNull(Price) and (Price < 0) then
    begin
      Cell.BackColor := $FFFFE0E0;
      Cell.CellFontColor := TAlphaColors.Red;
      Cell.CellFontStyle := [TFontStyle.fsBold];
    end;
  end;
end;

See Example 1 for a complete example, with a computed column.

See Also

(C) 2026 Easygate, Lda