All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
Row

ConditionalFormattingCollection.AddExpressionConditionalFormatting(CellRange, ConditionalFormattingExpressionCondition, String) Method

Applies the conditional formatting rule that uses a relational operator to determine which cells to format.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v21.1.Core.dll

Declaration

ExpressionConditionalFormatting AddExpressionConditionalFormatting(
    CellRange range,
    ConditionalFormattingExpressionCondition condition,
    string value
)

Parameters

Name Type Description
range CellRange

A CellRange object that specifies a range of cells to which the conditional formatting rule is applied.

condition ConditionalFormattingExpressionCondition

One of the ConditionalFormattingExpressionCondition enumeration values.

value String

A String value representing the threshold. This value can specify a formula to evaluate the threshold. If you use a formula, start it with an equal sign (=). The formula can include the spreadsheet’s built-in functions. You can combine relative and absolute references to adjust the formula in each cell.

Returns

Type Description
ExpressionConditionalFormatting

An ExpressionConditionalFormatting object that represents the specified conditional format.

Example

This example demonstrates how to create the rule that uses a relational operator as a formatting criteria.

  1. To create a new conditional formatting rule represented by the ExpressionConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddExpressionConditionalFormatting method. Pass the following parameters:

    • A CellRange object that defines a range of cells to which the rule is applied.
    • A condition specified by one of the ConditionalFormattingExpressionCondition enumeration values.
    • A string that specifies the threshold value. Notice that the string can determine a formula to evaluate the threshold.
  2. Specify formatting options to be applied to cells if the condition is true, using the ISupportsFormatting.Formatting property of the ExpressionConditionalFormatting object. Set the background and font colors.

To remove the ExpressionConditionalFormatting object, use the ConditionalFormattingCollection.Remove, ConditionalFormattingCollection.RemoveAt or ConditionalFormattingCollection.Clear methods.

' Create the rule to identify values that are above the average in cells F2 through F15.
Dim cfRule As ExpressionConditionalFormatting = worksheet.ConditionalFormattings.AddExpressionConditionalFormatting(worksheet.Range("$F$2:$F$15"), ConditionalFormattingExpressionCondition.GreaterThan, "=AVERAGE($F$2:$F$15)")
' Specify formatting options to be applied to cells if the condition is true.
' Set the background color to yellow.
cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, &HFA, &HF7, &HAA)
' Set the font color to red.
cfRule.Formatting.Font.Color = Color.Red
See Also