TdxSpreadSheetCustomConditionalFormatting.Add(TRect,TdxSpreadSheetCustomConditionalFormattingRuleClass,Untyped) Method
Creates a new rule and applies it to the specified cell range.
#Declaration
procedure Add(const AArea: TRect; ARuleClass: TdxSpreadSheetCustomConditionalFormattingRuleClass; out ARule); overload;
#Parameters
Name | Type | Description |
---|---|---|
AArea | TRect | The target cell range. |
ARule |
Tdx |
The reference to the required terminal Tdx |
ARule | Returns the created rule as an untyped reference (in Delphi) or pointer (in C++Builder). Pass an uninitialized reference (in Delphi) or pointer (in C++Builder) to an object of the conditional formatting rule type specified through the |
#Remarks
Call the Add
procedure to create a new conditional formatting rule of the required type and add the rule to the conditional formatting controller.
Alternatively, you can call the constructor of the required rule class and pass the current conditional formatting controller as a parameter.
Tip
You can use the Rules property to access all rules created in the conditional formatting controller.
#Code Example: Create and Configure Two Conditional Formatting Rules
The following code example creates Duplicate and Unique value conditional formatting rules with different custom cell styles and applies these rules to the last selected cell range in the active worksheet in a TdxSpreadSheet control:
var
ATableView: TdxSpreadSheetTableView;
ADuplicateValuesRule: TdxSpreadSheetConditionalFormattingRuleDuplicateValues;
AUniqueValuesRule: TdxSpreadSheetConditionalFormattingRuleUniqueValues;
begin
ATableView := dxSpreadSheet1.ActiveSheetAsTable;
if ATableView.Selection.Count = 0 then Exit;
ATableView.ConditionalFormatting.BeginUpdate; // Initiates the following batch change
try
ATableView.ConditionalFormatting.Add(ATableView.Selection.Area,
TdxSpreadSheetConditionalFormattingRuleDuplicateValues, ADuplicateValuesRule);
ADuplicateValuesRule.Style.Brush.BackgroundColor := clBlue;
ADuplicateValuesRule.Style.Brush.ForegroundColor := clNavy;
ADuplicateValuesRule.Style.Brush.Style := sscfsRevDiagonalStrip;
ADuplicateValuesRule.Style.Font.Color := clWhite;
ADuplicateValuesRule.Style.Font.Style := [fsBold, fsItalic];
ATableView.ConditionalFormatting.Add(ATableView.Selection.Area,
TdxSpreadSheetConditionalFormattingRuleUniqueValues, AUniqueValuesRule);
AUniqueValuesRule.Style.Brush.BackgroundColor := clLime;
AUniqueValuesRule.Style.Brush.ForegroundColor := clGreen;
AUniqueValuesRule.Style.Brush.Style := sscfsDiagonalStrip;
AUniqueValuesRule.Style.Font.Color := clWhite;
AUniqueValuesRule.Style.Font.Style := [fsBold];
finally
ATableView.ConditionalFormatting.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
end;
end;