TcxGridGetCellStyleEvent Type
The procedural type for cell style customization events.
Declaration
TcxGridGetCellStyleEvent = procedure(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; var AStyle: TcxStyle) of object;
Parameters
Name | Type | Description |
---|---|---|
Sender | TcxCustomGridTableView | Provides access to the grid View that raised the current cell style customization event. To access all public API members, cast the Tip You can call the |
ARecord | TcxCustomGridRecord | Provides access to the parent record of the processed cell. This parameter returns |
AItem | TcxCustomGridTableItem | Provides access to the parent data item of the processed cell. This parameter returns |
AStyle | TcxStyle | Specifies the style applied to the processed cell. Tip Assign an existing TcxStyle class instance to the |
Remarks
A cell style customization event occurs every time a grid View is about to draw a cell. You can handle cell style customization events to assign different styles to individual cells depending on specific conditions in your application.
Important
Since the style customization event can be frequent, its handler should avoid time-consuming calculations to prevent slowing down the application’s UI.
If you need to rely on data-dependent conditions in a style customization event handler, we strongly recommend that you use only cached or pre-calculated values rather than complex calculations at the data controller or dataset level.
Code Example
The code example in this topic applies cxStyleGroup1 and cxStyleGroup2 styles to data rows whose cells contain Group1
and Group2
values.
Follow the steps below to test this code example in your RAD Studio IDE:
- Copy the DFM code snippet below.
- Create a new project in the IDE and focus an empty form.
- Press Ctrl+V to populate the form with preconfigured components.
- Expand the Styles node in the Events tab of the Object Inspector.
- Create an empty OnGetContentStyle event handler, paste the code example, and run the project.
object cxGrid1: TcxGrid
Left = 72
Top = 80
Width = 545
Height = 200
TabOrder = 0
object cxGrid1DBTableView1: TcxGridDBTableView
Navigator.Buttons.CustomButtons = <>
ScrollbarAnnotations.CustomAnnotations = <>
DataController.DataSource = DataSource1
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
Styles.OnGetContentStyle = cxGrid1DBTableView1StylesGetContentStyle
object cxGrid1DBTableView1RecId: TcxGridDBColumn
DataBinding.FieldName = 'RecId'
Visible = False
end
object cxGrid1DBTableView1Groups: TcxGridDBColumn
DataBinding.FieldName = 'Groups'
end
object cxGrid1DBTableView1Names: TcxGridDBColumn
DataBinding.FieldName = 'Names'
end
object cxGrid1DBTableView1Values: TcxGridDBColumn
DataBinding.FieldName = 'Values'
Width = 54
end
end
object cxGrid1Level1: TcxGridLevel
GridView = cxGrid1DBTableView1
end
end
object dxMemData1: TdxMemData
Active = True
Indexes = <>
Persistent.Data = {
5665728FC2F5285C8FFE3F04000000140000000100070047726F757073001400
0000010006004E616D657300040000000300070056616C756573000400000009
000600446174657300010600000047726F75703101050000004E616D6531010A
000000017B000B00010600000047726F75703101050000004E616D6532011400
000001CF0E0B00010600000047726F75703201050000004E616D6533011E0000
00017A210B00010600000047726F75703201050000004E616D65340128000000
01892B0B00}
SortOptions = []
Left = 520
Top = 88
object dxMemData1Groups: TStringField
FieldName = 'Groups'
end
object dxMemData1Names: TStringField
FieldName = 'Names'
end
object dxMemData1Values: TIntegerField
FieldName = 'Values'
end
object dxMemData1Dates: TDateField
FieldName = 'Dates'
end
end
object DataSource1: TDataSource
DataSet = dxMemData1
Left = 472
Top = 176
end
object cxStyleRepository1: TcxStyleRepository
Left = 520
Top = 144
PixelsPerInch = 96
object cxStyleGroup1: TcxStyle
AssignedValues = [svColor]
Color = clRed
end
object cxStyleGroup2: TcxStyle
AssignedValues = [svColor]
Color = clLime
end
end
procedure TMyForm.cxGrid1DBTableView1StylesGetContentStyle(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; var AStyle: TcxStyle);
var
AValue: Variant;
begin
if ((ARecord <> nil) and (AItem <> nil)) then
begin
AValue := ARecord.Values[cxGrid1DBTableView1Groups.Index];
if AValue = 'Group1' then
AStyle := cxStyleGroup1
else if AValue = 'Group2' then
AStyle := cxStyleGroup2;
end;
end;
Important Limitations
- You can only assign a background bitmap for the entire grid View through the Content.Bitmap property. An OnGetContentStyle event handler cannot define different background bitmaps for individual cells.
- Do not perform any operations at the dataset level within an OnGetContentStyle event handler. These operations may move focus and send other notifications that can trigger an infinite loop.
Direct TcxGridGetCellStyleEvent Type Reference
The following events reference the TcxGridGetCellStyleEvent
procedural type:
- TcxCustomGridTableViewStyles.OnGetContentStyle
- Allows you to change the content style of individual cells depending on specific conditions in your application.
- TcxCustomGridTableItemStyles.OnGetContentStyle
- Occurs whenever an item cell should be redrawn.