[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Collapse]Spreadsheet Document API
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
  [Expand]Formulas
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Charts and Graphics
  [Expand]Mail Merge
  [Collapse]Examples
   [Expand]Files
   [Expand]Workbooks
   [Expand]Worksheets
   [Expand]Rows and Columns
   [Expand]Cells
   [Expand]Formulas
   [Expand]Import and Export Data
   [Expand]Data Binding
    Sorting
   [Expand]Mail Merge
    Search
   [Expand]Shapes
   [Expand]Charts
   [Expand]Sparklines
   [Expand]Formatting Cells
   [Collapse]Conditional Formatting
     How to: Format Cell Values that are Above or Below the Average
     How to: Format Cells that are Between or Not Between Two Values
     How to: Format Top or Bottom Ranked Values
     How to: Format Cells based on the Text in the Cell
     How to: Format Unique or Duplicate Values, Blank Cells and Formula Errors
     How to: Format Cells that Contain Dates
     How to: Format Cells that are Less than, Greater than or Equal to a Value
     How to: Use a Formula to Determine which Cells to Format
     How to: Format Cells Using a Two-Color Scale
     How to: Format Cells Using a Three-Color Scale
     How to: Format Cells Using Data Bars
     How to: Format Cells Using Icon Sets
   [Expand]Group Data
   [Expand]Filter Data
   [Expand]Tables
   [Expand]Pivot Tables
   [Expand]Printing
   [Expand]Pictures
   [Expand]Protection
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Format Cells that are Less than, Greater than or Equal to a Value

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 Range 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.

The image below shows the result (the workbook is opened in Microsoft® Excel®). Price values above the average are highlighted in yellow with red font.

Is this topic helpful?​​​​​​​