TcxDataControllerConditionalFormatting.Add(string,TdxSpreadSheetCustomConditionalFormattingRuleClass,Untyped) Method
Creates a new conditional formatting rule and applies it to the required field by its name.
#Declaration
procedure Add(const AFieldName: string; ARuleClass: TdxSpreadSheetCustomConditionalFormattingRuleClass; out ARule); overload;
#Parameters
Name | Type | Description |
---|---|---|
AField |
string | The name of the target field in the source data controller. |
ARule |
Tdx |
The reference to the required conditional formatting rule class (a Tdx |
ARule | The created conditional formatting rule. |
#Remarks
Call the Add
procedure to apply a conditional formatting rule to any data item (a Tree List or Data Grid column, or a Vertical Grid row).
Alternatively, you can call the constructor of the required conditional formatting rule class and pass the conditional formatting controller as a parameter.
#Code Example: Apply a Data Bar Conditional Formatting Rule to a Data Grid Column
The following code example creates a data bar conditional formatting rule and applies it to a column in a TcxGrid control’s data-aware Table View:
var
ARule: TdxSpreadSheetConditionalFormattingRuleDataBar;
begin
cxGrid1DBTableView1.ConditionalFormatting.Add(cxGrid1DBTableView1Column1.Caption,
TdxSpreadSheetConditionalFormattingRuleDataBar, ARule);
ARule.BeginUpdate; // Initiates the following batch change
try
ARule.Style.NegativeBarColor := clRed;
ARule.Style.NegativeBarBorderColor := clRed;
ARule.Style.PositiveBarColor := clGreen;
ARule.Style.PositiveBarBorderColor := clGreen;
ARule.Style.FillMode := dbfmSolid;
finally
ARule.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
end;
end;
#Delete a Conditional Formatting Rule
To delete a conditional formatting rule, you can call the Remove procedure or release the rule directly in code (call the Free procedure in Delphi or use the delete
keyword in C++Builder).