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

TcxDataControllerConditionalFormatting.Add(Integer,TdxSpreadSheetCustomConditionalFormattingRuleClass,Untyped) Method

Creates a new conditional formatting rule and applies it to the required field by its index.

#Declaration

Delphi
procedure Add(const AFieldIndex: Integer; ARuleClass: TdxSpreadSheetCustomConditionalFormattingRuleClass; out ARule); overload;

#Parameters

Name Type Description
AFieldIndex Integer

The index of the target field in the source data controller.

ARuleClass TdxSpreadSheetCustomConditionalFormattingRuleClass

The reference to the required conditional formatting rule class (a TdxSpreadSheetCustomConditionalFormattingRule descendant).

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 an Icon Set Conditional Formatting Rule to a Data Grid Column

The following code example creates an Icon Set conditional formatting rule with three threshold values and applies the rule to the first column in a TcxGrid control’s data-aware Table View:

var
  ARule: TdxSpreadSheetConditionalFormattingRuleIconSet;
begin
  cxGrid1DBTableView1.ConditionalFormatting.Add(0, TdxSpreadSheetConditionalFormattingRuleIconSet, ARule);
  ARule.BeginUpdate;  // Initiates the following batch change
  try
    ARule.PresetName := ConditionalFormattingIconSet.Presets.Items[1].Name;
    ARule.Stops[0].ValueType := cssvtValue;
    ARule.Stops[0].Value := 0;
    ARule.Stops[1].ValueType := cssvtValue;
    ARule.Stops[1].Value := 25;
    ARule.Stops[2].ValueType := cssvtValue;
    ARule.Stops[2].Value := 50;
  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).

See Also