ConditionalFormattingCollection.AddRangeConditionalFormatting(CellRange, ConditionalFormattingRangeCondition, String, String) Method
Applies the conditional formatting rule that formats cells which are between or not between two specified values.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
RangeConditionalFormatting AddRangeConditionalFormatting(
CellRange range,
ConditionalFormattingRangeCondition condition,
string lowBound,
string highBound
)
Parameters
Name | Type | Description |
---|---|---|
range | CellRange | A CellRange object that specifies a range of cells to which the conditional formatting rule is applied. |
condition | ConditionalFormattingRangeCondition | One of the ConditionalFormattingRangeCondition enumeration values. |
lowBound | String | A String value that is the low bound of the subset inside or outside of which, formatted cells are located. The string can specify a formula to evaluate the low bound. 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 if necessary. |
highBound | String | A String value that is the maximum value in the subset inside or outside of which, formatted cells are located. The string can specify a formula to evaluate the high bound. 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 |
---|---|
RangeConditionalFormatting | A RangeConditionalFormatting object that represents the specified conditional format. |
Example
This example demonstrates how to apply the conditional formatting rule, highlighting cells that are between or not between two values.
To create a new conditional formatting rule represented by the RangeConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the
ConditionalFormattingCollection.AddRangeConditionalFormatting
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 ConditionalFormattingRangeCondition enumeration values.
- A string representing the low bound of the data subset inside or outside of which, formatted cells are located. Notice that the string can determine a formula to evaluate the lowest value.
- A string representing the high bound of the data subset inside or outside of which, formatted cells are located. Notice that the string can determine a formula to evaluate the highest value.
- Specify formatting options to be applied to cells if the condition is true using the ISupportsFormatting.Formatting property of the RangeConditionalFormatting object. Set the background and font colors.
Note
Transparency is not supported in conditional formatting.
To remove the RangeConditionalFormatting object, use the ConditionalFormattingCollection.Remove, ConditionalFormattingCollection.RemoveAt or ConditionalFormattingCollection.Clear methods.
// Create the rule to identify values below 7 and above 19 in cells F2 through F15.
RangeConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddRangeConditionalFormatting(worksheet.Range["$F$2:$F$15"], ConditionalFormattingRangeCondition.Outside, "7", "19");
// 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, 0xFA, 0xF7, 0xAA);
// Set the font color to red.
cfRule.Formatting.Font.Color = Color.Red;
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the AddRangeConditionalFormatting(CellRange, ConditionalFormattingRangeCondition, String, String) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.