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.AddTextConditionalFormatting(CellRange, ConditionalFormattingTextCondition, String) Method

Applies the conditional formatting rule that formats cells based on the text they contain.

Namespace: DevExpress.Spreadsheet

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

Declaration

TextConditionalFormatting AddTextConditionalFormatting(
    CellRange range,
    ConditionalFormattingTextCondition condition,
    string text
)

Parameters

Name Type Description
range CellRange

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

condition ConditionalFormattingTextCondition

One of the ConditionalFormattingTextCondition enumeration values.

text String

A String value that represents text to be used as a formatting criterion. This value can also specify a formula that returns text. If you use a formula, start it with an equal sign (=).

Returns

Type Description
TextConditionalFormatting

An IconSetConditionalFormatting object that represents the specified conditional format.

Example

This example demonstrates how to create a rule that applies a conditional format based on the text in a cell.

  1. To create a new conditional formatting rule represented by the TextConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddTextConditionalFormatting 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 ConditionalFormattingTextCondition enumeration values.
    • A text string to be highlighted in a range of cells.
  2. Specify formatting options to be applied to cells if the condition is true using the ISupportsFormatting.Formatting property of the TextConditionalFormatting object.

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

' Create the rule to highlight values with the given text string in cells A2 through A15.
Dim cfRule As TextConditionalFormatting = worksheet.ConditionalFormattings.AddTextConditionalFormatting(worksheet.Range("$A$2:$A$15"), ConditionalFormattingTextCondition.Contains, "Bradbury")
' Specify formatting options to be applied to cells if the condition is true.
' Set the background color to pink.
cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, &HE1, &H95, &HC2)
See Also