Back to Devexpress

Formatting Values Using Color Scales

wpf-118923-controls-and-libraries-data-grid-conditional-formatting-conditional-formats-formatting-values-using-color-scales.md

latest4.9 KB
Original Source

Formatting Values Using Color Scales

  • Aug 27, 2019
  • 3 minutes to read

The Color Scales conditional format allows you to use predefined or custom color sets to format different ranges of values.

The image below shows a grid column whose Profit cells are colored according to their values.

This topic consists of the following sections:

Adding Rules in Code

Create the ColorScaleFormatCondition class instance and specify the following settings to create a conditional format in code:

The following code sample illustrates how to define a conditional format in markup:

xaml
<dxg:TableView.FormatConditions>
   <dxg:ColorScaleFormatCondition FieldName="Profit" PredefinedFormatName="RedWhiteBlueColorScale"/>
</dxg:TableView.FormatConditions>

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

csharp
var profitFormatCondition = new ColorScaleFormatCondition() {
   FieldName = "Profit",
   PredefinedFormatName = "RedWhiteBlueColorScale"
};
view.FormatConditions.Add(profitFormatCondition);
vb
Dim profitFormatCondition = New ColorScaleFormatCondition() With {
   .FieldName = "Profit",
   .PredefinedFormatName = "RedWhiteBlueColorScale"
}
view.FormatConditions.Add(profitFormatCondition)

Adding Rules Using Conditional Formatting Menu

  1. Select the Color Scales item in the Conditional Formatting Menu.
  2. Choose the required color set in the invoked sub menu. The conditional formatting menu allows you to use only predefined Color Scales formats stored within the TableView.PredefinedColorScaleFormats (or TreeListView.PredefinedColorScaleFormats) collection.

Adding Rules Using Conditional Formatting Rules Manager

  1. Click the New Rule… in the Conditional Formatting Rules Manager.

  2. Select the Format all cells based on their values rule in the invoked New Formatting Rule dialog.

  3. Select the 2-Color Scale or 3-Color Scale format style.

  4. Specify the Type and Value fields. These options determine the conditional values on which formatting of cells/rows is based.

  5. Specify the Min Value and Max Value fields to determine the range of values used in formatting. These fields are optional. The range is calculated automatically based on maximum and minimum values from cell values by default.

  6. Specify the Color fields to define the visual appearance of the applied rule.

See Also

Conditional Formats

Conditional Formatting Menu

Conditional Formatting Rules Manager