[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Implementation Details
   [Expand]Views
   [Expand]Grid View Data Layout
   [Expand]Binding to Data
   [Expand]Master-Detail Data Representation
   [Expand]Data Editing and Validation
   [Expand]Grouping
   [Expand]Filtering and Searching
   [Expand]Sorting
   [Expand]Data Summaries
   [Expand]Paging and Scrolling
   [Expand]Focus, Navigation, Selection
   [Expand]Drag-and-Drop
   [Collapse]Conditional Formatting
     Conditional Formats
     Creating Conditional Formatting Rules
     Conditional Formatting Menu
     Conditional Formatting Rules Manager
     Formatting Values Using Comparison Rules
     Formatting Date-Time Values
     Formatting Unique and Duplicate Values
     Formatting Top and Bottom Values
     Formatting Above or Below Average Values
     Formatting Changing Values
     Formatting Values Using Icon Sets
     Formatting Values Using Color Scales
     Formatting Values Using Data Bars
     Formatting Values Using Custom Conditions
     Formatting Focused Cells and Rows
     Examples
   [Expand]Appearance Customization
   [Expand]MVVM Enhancements
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Miscellaneous
   [Expand]Performance Improvement
   [Expand]Design-Time Features
   [Expand]Visual Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[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)

Conditional Formats

Conditional formats (conditional formatting rules) allow you to apply specified formatting only when certain conditions are met.

The image above shows the grid column whose Profit cells are green if their values are greater than 10M, i.e. the conditional format with the following settings is applied:

  • Format - Green Fill with Dark Green Text
  • Condition - Profit values are greater than 10M

Expanded Conditional Formats Overview

The table below shows the following FormatConditionBase class descendants that represent the conditional formats.

Class

Conditional Formats

FormatCondition

The Value Based rules format cells comparing cell values with static values.

The Date Occurring rules highlight date-time values that fall into a specified interval.

The Custom Condition uses a custom expression to apply conditional formatting.

UniqueDuplicateRuleFormatCondition

The Unique-Duplicate rules format cells whose values are unique or duplicate.

TopBottomRuleFormatCondition

The Top-Bottom rules highlight a specific number of topmost/bottommost values.

The Average rules format cells whose values are above or below an average value.

DataUpdateFormatCondition

The Data Update rules visualize changing values in real time.

IconSetFormatCondition

The Icon Sets rules use sets of icons to format different ranges of values.

ColorScaleFormatCondition

The Color Scales rules use sets of colors to format different ranges of values.

DataBarFormatCondition

The Data Bars rules visualize values using bars.

Expanded Creating Conditional Formats

Refer to the Creating Conditional Formatting Rules topic to learn how to create conditional formats.

Expanded Binding to a Collection of Conditional Formats

The grid's view supports binding to a collection of objects containing conditional format settings. This collection of objects can be described in Model or ViewModel.

Specify the TableView.FormatConditionsSource (or TreeListView.FormatConditionsSource) property to assign the source from which the grid generates conditional formats. See the Binding to a Collection of Conditional Formatting Rules topic to learn more.

Expanded Specifying Formats

Creating Custom Formats

Create the required format class instance, specify its settings, and assign the resulting object to the conditional format's Format property. The table below lists conditional formats with corresponding format classes.

Conditional Format Format Class Format Property
Basic conditional formats Format ExpressionConditionBase.Format
Data Update Format DataUpdateFormatCondition.Format
Icon Sets IconSetFormat IconSetFormatCondition.Format
Color Scales ColorScaleFormat ColorScaleFormatCondition.Format
Data Bars DataBarFormat DataBarFormatCondition.Format

The following code sample illustrates how to create a conditional formatting rule with a custom format in markup.

The code sample below illustrates how to define the same conditional formatting rule in code-behind.

Using Predefined Formats

Specify the conditional format's FormatConditionBase.PredefinedFormatName property.

The table below presents the collections that store predefined formats.

Conditional Format Predefined Formats Collection
Basic conditional formats TableView.PredefinedFormats (TreeListView.PredefinedFormats)
Data Update TableView.PredefinedFormats (TreeListView.PredefinedFormats)
Icon Sets TableView.PredefinedIconSetFormats (TreeListView.PredefinedIconSetFormats)
Color Scales TableView.PredefinedColorScaleFormats (TreeListView.PredefinedColorScaleFormats)
Data Bars TableView.PredefinedDataBarFormats (TreeListView.PredefinedDataBarFormats)

You cannot modify a predefined format collection. To define a new predefined format, create a new predefined format collection.

The following code sample illustrates how to create a collection of predefined formats in markup.

The code sample below illustrates how to create a collection of predefined formats in code-behind.

Expanded Specifying Conditions

Using Rules

Choose the required conditional format (see the table in the Conditional Formats Overview section). Depending on the chosen conditional format, specify a rule for the conditional format, if necessary.

The following code sample illustrates how to define a conditional format with rule in markup.

The code sample below illustrates how to define the same conditional format in code-behind.

Creating Custom Expressions

Specify the conditional format's FormatConditionBase.Expression property. Refer to the Formatting Values Using Custom Conditions topic to learn more.

The following code sample illustrates how to define a conditional format with an expression in markup.

The code sample below illustrates how to define the same conditional format in code-behind.

Expanded Conditional Formatting Transition Animation

The GridControl allows applying conditional formatting with an animation effect. See the How to: Change a Modified Cell Appearance example to learn more.

You can enable animation effects as follows:

To define specific animation effects for a conditional format, create the ConditionalFormattingAnimationSettings class instance with the required settings and assign the resulting object to the conditional format's ExpressionConditionBase.AnimationSettings (or IndicatorFormatConditionBase.AnimationSettings) property.

The following code sample illustrates how to define specific animation effects for a conditional format in markup.

The code sample below illustrates how to define the same animation effects for a conditional format in code-behind.

To define the duration of animation effect transition for all conditional formats within the current grid's view, specify the TableView.ConditionalFormattingTransitionDuration (TreeListView.ConditionalFormattingTransitionDuration) property.

Tip

The Data Update conditional format has specific animation settings. Refer to Data Update Animation section of the Formatting Changing Values topic to learn how specify animation for changing values.

Expanded See Also

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