Skip to main content
A newer version of this page is available. .

TcxCustomGridTableViewStyles.OnGetContentStyle Event

Enables you to override the default style of a cell for specific items and/or records.

Declaration

property OnGetContentStyle: TcxGridGetCellStyleEvent read; write;

Remarks

The cell being painted is addressed by its record (ARecord) and item (AItem). If the OnGetContentStyle event is fired for a View element that is not associated with an item or cell (for instance, a group row), the AItem parameter value is nil.

The Sender parameter determines the Table View for which the content is being repainted.

The default cell style is determined based on the View’s Styles.Content, Styles.ContentEven and Styles.ContentOdd properties.

To redefine the style for a specific item/record, you need to assign it to the AStyle parameter. Use the TcxStyleRepository component as a convenient way to create, delete and modify individual styles.

The following code sets different styles (cxStyle1 and cxStyle2) for odd and even Card View items (card rows). The styles are created via the style repository. They specify different background and text colors:

procedure Form1.cxGridUsersDBCardViewStylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
  if (Assigned(AItem) And Odd(AItem.VisibleIndex)) then
    AStyle := cxStyle1
  else
    AStyle := cxStyle2;
end;

Note

The background bitmap cannot be assigned by handling the OnGetContentStyle event as this is relevant only to all the cells within the grid.

See Also