Back to Devexpress

TdxSpreadSheetConditionalFormattingRuleDuplicateValues Class

vcl-dxspreadsheetconditionalformattingrules-e2e2e3a8.md

latest12.2 KB
Original Source

TdxSpreadSheetConditionalFormattingRuleDuplicateValues Class

A Duplicate Values conditional formatting rule.

Declaration

delphi
TdxSpreadSheetConditionalFormattingRuleDuplicateValues = class(
    TdxSpreadSheetConditionalFormattingRuleStyleBased
)

Remarks

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

Main API Members

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

Common Rule API Members

AreasAllows you to manage the conditional formatting rule’s target areas.CloneCopies the rule between different sets of target areas.Index | StopIfTrueSpecify how the rule interacts with other conditional formatting rules applied to the same cells.

Duplicate Values Rule-Specific API Members

StyleAllows you to define the appearance of formatted cells.

General-Purpose API Members

AssignCopies compatible settings between conditional formatting rules.BeginUpdate | EndUpdateAllow you to avoid excessive redraw operations during batch rule setting changes.GetDetailsReturns the conditional formatting rule’s name displayed in the Conditional Formatting Rules Manager dialog.LoadFromStream | SaveToStreamAllow you to store conditional formatting rule settings in a stream.OwnerProvides access to the parent conditional formatting controller.

Create a Duplicate Values Rule

To create a Duplicate 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 TdxSpreadSheetConditionalFormattingRuleDuplicateValues class as the ARuleClass parameter:

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

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

Delete a Conditional Formatting Rule

To delete an individual Duplicate Values conditional formatting rule, you can 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:

TdxSpreadSheetConditionalFormattingRuleAboveOrBelowAverageAn Above or Below Average conditional formatting rule.TdxSpreadSheetConditionalFormattingRuleCellIsA Cell Is conditional formatting rule.TdxSpreadSheetConditionalFormattingRuleExpressionAn Expression conditional formatting rule.TdxSpreadSheetConditionalFormattingRuleTopBottomValuesA Top/Bottom Values conditional formatting rule.TdxSpreadSheetConditionalFormattingRuleUniqueValuesA Unique Values conditional formatting rule.

Code Example: Create Duplicate and Unique Value Conditional Formatting Rules in Spreadsheet

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:

delphi
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;
cpp
TdxSpreadSheetTableView *ATableView;
  TdxSpreadSheetConditionalFormattingRuleDuplicateValues *ADuplicateValuesRule;
  TdxSpreadSheetConditionalFormattingRuleUniqueValues *AUniqueValuesRule;
  // ...
  ATableView = dxSpreadSheet1->ActiveSheetAsTable;
  if(ATableView->Selection->Count == 0) { return; }
  ATableView->ConditionalFormatting->BeginUpdate(); // Initiates the following batch change
  try
  {
    ATableView->ConditionalFormatting->Add(ATableView->Selection->Area,
    __classid(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 = TFontStyles() << fsBold << fsItalic;
    ATableView->ConditionalFormatting->Add(ATableView->Selection->Area,
    __classid(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 = TFontStyles() << fsBold;
  }
  __finally
  {
    ATableView->ConditionalFormatting->EndUpdate(); // Calls EndUpdate reagrdless of the batch operation's success
  }

Indirect TdxSpreadSheetConditionalFormattingRuleDuplicateValues Class References

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

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

Inheritance

TObject TPersistent TInterfacedPersistent TcxInterfacedPersistent TdxSpreadSheetCustomConditionalFormattingRule TdxSpreadSheetConditionalFormattingCustomRule TdxSpreadSheetConditionalFormattingRuleStyleBased TdxSpreadSheetConditionalFormattingRuleDuplicateValues

See Also

TdxSpreadSheetConditionalFormattingRuleCustomScale Class

TdxSpreadSheetConditionalFormattingRuleDuplicateValues Members

dxSpreadSheetConditionalFormattingRules Unit