Back to Devexpress

TdxSpreadSheetConditionalFormattingRuleDataBar Class

vcl-dxspreadsheetconditionalformattingrules-b01cd8bf.md

latest9.9 KB
Original Source

TdxSpreadSheetConditionalFormattingRuleDataBar Class

A Data Bar conditional formatting rule.

Declaration

delphi
TdxSpreadSheetConditionalFormattingRuleDataBar = class(
    TdxSpreadSheetConditionalFormattingRuleCustomScale
)

Remarks

A Data Bar rule visualizes all numeric values as horizontal bars within affected cells.

Main API Members

The list below outlines key members of the TdxSpreadSheetConditionalFormattingRuleDataBar class. These members allow you to configure Data Bar 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.

Rule-Specific API Members

MinValue | MaxValueSpecify minimum and maximum threshold values.ShowValueSpecifies if cell values are visible.StyleAllows you to customize bar appearance.

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 Data Bar Rule

To create a Data Bar conditional formatting rule, you can call one of the overloaded Add procedures of the corresponding conditional formatting controller and pass a reference to the TdxSpreadSheetConditionalFormattingRuleDataBar 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 TdxSpreadSheetConditionalFormattingRuleDataBar class and pass the target conditional formatting controller as the AOwner 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:

delphi
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;
cpp
TdxSpreadSheetConditionalFormattingRuleDataBar *ARule;
// ...
  cxGrid1DBTableView1->ConditionalFormatting->Add(cxGrid1DBTableView1Column1->Caption,
           __classid(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
  }

Delete a Conditional Formatting Rule

To delete an individual Data Bar 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 Threshold-Based Conditional Formatting Rule Classes

You can also use the following threshold-based rules:

TdxSpreadSheetConditionalFormattingRuleIconSetAn Icon Set conditional formatting rule.TdxSpreadSheetConditionalFormattingRuleThreeColorScaleA Three Color Scale conditional formatting rule.TdxSpreadSheetConditionalFormattingRuleTwoColorScaleA Two Color Scale conditional formatting rule.

Indirect TdxSpreadSheetConditionalFormattingRuleDataBar Class References

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

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

Inheritance

TObject TPersistent TInterfacedPersistent TcxInterfacedPersistent TdxSpreadSheetCustomConditionalFormattingRule TdxSpreadSheetConditionalFormattingCustomRule TdxSpreadSheetConditionalFormattingRuleCustomScale TdxSpreadSheetConditionalFormattingRuleDataBar

See Also

TdxSpreadSheetConditionalFormattingRuleStyleBased Class

TdxSpreadSheetConditionalFormattingRuleDataBar Members

dxSpreadSheetConditionalFormattingRules Unit