Skip to main content

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 Sender parameter value to the corresponding terminal TcxCustomGridTableView class descendant.

Tip

You can call the Sender.ClassType function to identify the actual grid View type.

ACanvas TcxCanvas

Provides access to the canvas of the target auxiliary cell.

You can call draw methods accessible through the ACanvas parameter to display custom content in the processed cell. Use the ViewInfo parameter to obtain additional information required to draw cell content, such as cell boundaries.

AViewInfo TcxGridTableCellViewInfo

Returns information required to identify and draw the processed cell.

Use AViewInfo.Item and AViewInfo.GridRecord properties to identify the position of the processed cell in the parent grid View. To obtain calculated cell boundaries, use the AViewInfo.Bounds field.

ADone Boolean
False
Default. Built-in draw routines display the processed cell according to active skin and appearance settings.
True
Built-in draw routines are disabled for the processed cell. Use this option if you need to draw a cell from scratch.

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:

VCL Data Grid: A Grid Table View with Group Rows

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;

VCL Data Grid: A Custom Group Row Appearance Example

Direct TcxGridTableCellCustomDrawEvent Type Reference

The TcxGridTableView.OnCustomDrawGroupCell event references the TcxGridTableCellCustomDrawEvent procedural type.

See Also