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.AddRankConditionalFormatting(CellRange, ConditionalFormattingRankCondition, Int32) Method

Applies the "top/bottom N" conditional formatting rule.

Namespace: DevExpress.Spreadsheet

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

Declaration

RankConditionalFormatting AddRankConditionalFormatting(
    CellRange range,
    ConditionalFormattingRankCondition condition,
    int rank
)

Parameters

Name Type Description
range CellRange

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

condition ConditionalFormattingRankCondition

One of the ConditionalFormattingRankCondition enumeration values that represent top/bottom rules.

rank Int32

A positive integer that is a number or percentage of the rank value to be set in the conditional formatting rule.

Returns

Type Description
RankConditionalFormatting

A RankConditionalFormatting object that represents the specified conditional format.

Example

This example demonstrates how to apply a "top/bottom N" conditional formatting rule.

  1. To create a new conditional formatting rule represented by the RankConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddRankConditionalFormatting 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 ConditionalFormattingRankCondition enumeration values.
    • A positive integer value representing the number or percentage of the rank value.
  2. Specify formatting options to be applied to cells if the condition is true, using the ISupportsFormatting.Formatting property of the RankConditionalFormatting object. Define the background and font colors, and set the outline borders.

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

' Create the rule to identify top three values in cells F2 through F15.
Dim cfRule As RankConditionalFormatting = worksheet.ConditionalFormattings.AddRankConditionalFormatting(worksheet.Range("$F$2:$F$15"), ConditionalFormattingRankCondition.TopByRank, 3)
' Specify formatting options to be applied to cells if the condition is true.
' Set the background color to dark orchid.
cfRule.Formatting.Fill.BackgroundColor = Color.DarkOrchid
' Set the outline borders.
cfRule.Formatting.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin)
' Set the font color to white.
cfRule.Formatting.Font.Color = Color.White
See Also