TcxGridTableCellCustomDrawEvent Type
The procedural type for auxiliary cell draw events.
Declaration
TcxGridTableCellCustomDrawEvent = procedure(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableCellViewInfo; var ADone: Boolean) of object;
Parameters
Name | Type | Description |
---|---|---|
Sender | TcxCustomGridTableView | Provides access to the grid View that raised the current cell draw event. To access all public API members, cast the Tip You can call the |
ACanvas | TcxCanvas | Provides access to the canvas of the target auxiliary cell. You can call draw methods accessible through the |
AViewInfo | TcxGridTableCellViewInfo | Returns information required to identify and draw the processed cell. Use |
ADone | Boolean |
|
Remarks
A cell’s custom draw event occurs every time the grid View is about to draw a cell. You can handle this event to change the appearance of individual cells depending on specific conditions in your application.
Important
Since custom draw events can be frequent, their handlers should avoid time-consuming calculations to prevent the application’s UI from slowing down.
If you need to rely on data-dependent conditions in a custom draw event handler, we strongly recommend that you use only cached or pre-calculated values rather than time-consuming calculations at the data controller or dataset level.
Code Example: Change Group Row Appearance Based on Content
Built-in draw routines display group rows according to active look & feel settings and other grid View options that affect group row appearance and layout:
The code example in this topic section demonstrates an OnCustomDrawGroupCell
event handler that implements a custom draw routine for group rows. This handler modifies font attributes and changes row background color depending on content:
uses
cxGrid, // Declares the TcxGrid control
cxGridTableView, // Declares the TcxGridTableView class
StrUtils; // Declares the ContainsText function
// ...
procedure TMyForm.cxGrid1TableView1CustomDrawGroupCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableCellViewInfo; var ADone: Boolean);
var
AString: string;
ARect: TRect;
begin
AString := AViewInfo.Text;
ARect := AViewInfo.Bounds;
ARect.Left := ARect.Left + AViewInfo.ScaleFactor.Apply(15);
ARect.Top := ARect.Top + AViewInfo.ScaleFactor.Apply(5);
if ContainsText(AViewInfo.Text, 'City') then
begin
ACanvas.Font.Style := [fsBold, fsItalic];
ACanvas.FillRect(AViewInfo.Bounds, clWebLightGreen);
end
else
begin
ACanvas.Font.Color := clWhite;
ACanvas.Font.Style := [fsBold];
ACanvas.FillRect(AViewInfo.Bounds, clWebLightCoral);
end;
ACanvas.DrawTexT(AString, ARect, 0, True);
ADone := True;
end;
Direct TcxGridTableCellCustomDrawEvent Type Reference
The TcxGridTableView.OnCustomDrawGroupCell event references the TcxGridTableCellCustomDrawEvent
procedural type.