Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TdxSpreadSheetConditionalFormattingRuleUniqueValues Class

A Unique Values conditional formatting rule.

#Declaration

Delphi
TdxSpreadSheetConditionalFormattingRuleUniqueValues = class(
    TdxSpreadSheetConditionalFormattingRuleStyleBased
)

#Remarks

A Unique Values conditional formatting rule applies custom appearance settings to all cells that contain unique values within target areas. The Unique Values rule complements Duplicate Values.

VCL Spreadsheet: A

#Main API Members

The list below outlines key members of the TdxSpreadSheetConditionalFormattingRuleUniqueValues class. These members allow you to configure Unique Values rule settings.

#Common Rule API Members

Areas
Allows you to manage the conditional formatting rule’s target areas.
Clone
Copies the rule between different sets of target areas.
Index | StopIfTrue
Specify how the rule interacts with other conditional formatting rules applied to the same cells.

#Rule-Specific API Members

Style
Allows you to define the appearance of formatted cells.

#General-Purpose API Members

Assign
Copies compatible settings between conditional formatting rules.
BeginUpdate | EndUpdate
Allow you to avoid excessive redraw operations during batch rule setting changes.
GetDetails
Returns the conditional formatting rule’s name displayed in the Conditional Formatting Rules Manager dialog.
LoadFromStream | SaveToStream
Allow you to store conditional formatting rule settings in a stream.
Owner
Provides access to the parent conditional formatting controller.

#Create a Unique Values Rule

To create a Unique Values conditional formatting rule, you can call one of the overloaded Add procedures of the corresponding conditional formatting controller and pass a reference to the TdxSpreadSheetConditionalFormattingRuleUniqueValues class as the ARuleClass parameter:

TcxDataControllerConditionalFormatting.Add
Creates a new conditional formatting rule for a Data Grid, Tree List, or Vertical Grid control.
TdxSpreadSheetConditionalFormatting.Add
Creates a new conditional formatting rule in a spreadsheet document.

Alternatively, you can call the constructor of the TdxSpreadSheetConditionalFormattingRuleUniqueValues class and pass the target conditional formatting controller as the AOwner parameter.

#Delete a Conditional Formatting Rule

To delete an individual Unique Values conditional formatting rule, do one of the following:

Alternatively, you can call the TdxSpreadSheetCustomConditionalFormatting.Clear procedure to delete all rules in a conditional formatting controller.

#Other Style-Based Conditional Formatting Rule Classes

You can also use the following style-based rules to apply spreadsheet-compatible style settings to cells that meet specific conditions:

TdxSpreadSheetConditionalFormattingRuleAboveOrBelowAverage
An Above or Below Average conditional formatting rule.
TdxSpreadSheetConditionalFormattingRuleCellIs
A Cell Is conditional formatting rule.
TdxSpreadSheetConditionalFormattingRuleDuplicateValues
A Duplicate Values conditional formatting rule.
TdxSpreadSheetConditionalFormattingRuleExpression
An Expression conditional formatting rule.
TdxSpreadSheetConditionalFormattingRuleTopBottomValues
A Top/Bottom Values conditional formatting rule.

#Code Example: Create Duplicate and Unique Value 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;

VCL Spreadsheet Controls: Unique and Duplicate Value Conditional Formatting Rules

#Indirect TdxSpreadSheetConditionalFormattingRuleUniqueValues Class References

The TdxSpreadSheetCustomConditionalFormatting.Rules property references the TdxSpreadSheetConditionalFormattingRuleUniqueValues class as a TdxSpreadSheetCustomConditionalFormattingRule object.

To access all public API members, cast the returned object to the TdxSpreadSheetConditionalFormattingRuleUniqueValues class. You can call the rule’s ClassType function to identify the actual rule type.

See Also