Skip to main content
Row

ConditionalFormattingCollection.AddColorScale2ConditionalFormatting(CellRange, ConditionalFormattingValue, Color, ConditionalFormattingValue, Color) Method

Applies the two-color scale conditional formatting rule.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v23.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

ColorScale2ConditionalFormatting AddColorScale2ConditionalFormatting(
    CellRange range,
    ConditionalFormattingValue minPoint,
    Color minPointColor,
    ConditionalFormattingValue maxPoint,
    Color maxPointColor
)

Parameters

Name Type Description
range CellRange

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

minPoint ConditionalFormattingValue

The ConditionalFormattingValue object that defines the minimum threshold and its ConditionalFormattingValueType type.

minPointColor Color

A Color object that defines a color representing the minimum value in the range of cells.

maxPoint ConditionalFormattingValue

The ConditionalFormattingValue object that defines the maximum threshold and its ConditionalFormattingValueType type.

maxPointColor Color

A Color object that defines a color representing the maximum value in the range of cells.

Returns

Type Description
ColorScale2ConditionalFormatting

A ColorScale2ConditionalFormatting object that represents the two-color scale conditional format.

Example

This example demonstrates how to apply a two-color scale conditional formatting rule.

  1. First of all, specify the minimum and maximum thresholds of a range using the ConditionalFormattingCollection.CreateValue method that creates an instance of the ConditionalFormattingValue object. This object provides access to threshold values and their types. The type of the threshold value is determined by one of the ConditionalFormattingValueType enumeration values and can be a number, percent, formula, or percentile. Call the ConditionalFormattingCollection.CreateValue method with the ConditionalFormattingValueType.MinMax parameter to set the minimum and maximum thresholds to the lowest and highest values in a range of cells, respectively.
  2. To apply a conditional formatting rule represented by the ColorScale2ConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddColorScale2ConditionalFormatting method with the following parameters:

    • A CellRange object that defines a range of cells to which the rule is applied.
    • A minimum threshold specified by the ConditionalFormattingValue object.
    • A color corresponding to the minimum value in a range of cells.
    • A maximum threshold specified by the ConditionalFormattingValue object.
    • A color corresponding to the maximum value in a range of cells.

    Note

    Transparency is not supported in conditional formatting.

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

View Example

ConditionalFormattingCollection conditionalFormattings = worksheet.ConditionalFormattings;
// Set the minimum threshold to the lowest value in the range of cells.
ConditionalFormattingValue minPoint = conditionalFormattings.CreateValue(ConditionalFormattingValueType.MinMax);
// Set the maximum threshold to the highest value in the range of cells.
ConditionalFormattingValue maxPoint = conditionalFormattings.CreateValue(ConditionalFormattingValueType.MinMax);
// Create the two-color scale rule to differentiate low and high values in cells C2 through D15. Blue represents the lower values and yellow represents the higher values. 
ColorScale2ConditionalFormatting cfRule = conditionalFormattings.AddColorScale2ConditionalFormatting(worksheet.Range["$C$2:$D$15"], minPoint, Color.FromArgb(255, 0x9D, 0xE9, 0xFA), maxPoint, Color.FromArgb(255, 0xFF, 0xF6, 0xA9));

The following code snippets (auto-collected from DevExpress Examples) contain references to the AddColorScale2ConditionalFormatting(CellRange, ConditionalFormattingValue, Color, ConditionalFormattingValue, Color) 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.

See Also