Events to customize cell’s font attributes and color
Events to customize cell’s font attributes and color
There are several events that allow you to customize cell’s font attributes and color before the cell data will be drawn. In the time of calling these events the DataSet is positioned on the record that need to draw, so in the events you can access field values using such methods as TDataSet.FieldByName(..).Value. Do not change grid properties or columns properties in these events. It can bring to recirculation of the program.
TDBGridEh.OnDrawColumnCell
TDBGridEh.OnDrawDataCell
TColumnEh.OnAdvDrawDataCell or TDBGridEh.OnAdvDrawDataCell
Write this event to draw data in the grid cell. In code of the event we set Processed parameter in True value to define that the process of drawing was performed in event. Otherwise grid will call method for default drawing of cell data. You may, if necessary, change such parameters as ARect or Params. After changing the parameters call Grid.DefaultDrawColumnDataCell method and set Processed to True value. You can also leave Processed parameter in False state and don’t call Grid.DefaultDrawColumnDataCell. In that case, grid will call default drawing procedure using changed parameters. Use Grid.Canvas property to draw data in the cell by yourself.
TDBGridEh.OnGetCellParams and TColumnEh.OnGetCellParams event
Parameters:
Sender: TObject
Column: TColumnEh
AFont : TFont
var Background: TColor
State: TGridDrawState
Write OnGetCellParams event to set such parameters as Font, cell color or other parameters of cell before cell will be drawn. If it is needed to change parameters only in a specified column then use column event - TColumnEh.OnGetCellParams. In this event you may change Font, Color, Alignment, ImageIndex, Text, checkbox's state and also such properties of a Params parameter as:
BlankCell: Boolean.
SuppressActiveCellColor: Boolean.
TextEditing: Boolean
These events are also called when grid request Font and Color for inplace editor.
If you want to draw data by yourself use OnAdvDrawDataCell event.
Use this event to replace the cell parameters for particular column before rendering. This event has an expanded set of parameters compared to the TDBGridEh.OnGetCellParams event.
This event is fired, not only before rendering a grid. In some cases, the event is called to request additional cell parameters. For example, before opening InplaceEditor grids causing the event and check Params.TextEditing option to allow you to open InplaceEditor for the current cell.
The TColumnEh.OnGetCellParams event has the following parameters :
Sender: TObject
Grid, which causes Event
EditMode: Boolean
The value is True if the event is caused by cell text editor. This same event is called when rendering a grid cell. In this case EditMode equals False.
Params: TColCellParamsEh
Additional parameters rendering. You can change the properties of this parameter in the event handler to change the format of the rendering of the current cell.
Alignment: TAlignment
Background: TColor
BlankCell: Boolean
SuppressActiveCellColor: Boolean
CheckboxState:TCheckBoxState
Col: Longint
CellRect: TRect
Font: TFont
ImageIndex: Integer
ReadOnly: Boolean
Row: Longint
State: TGridDrawState
Text: String
TextEditing: Boolean
DrawCellByThemes:Boolean
TextIsLink: Boolean
ImageIsLink: Boolean
