Skip to main content

Formatting Values Using Icon Sets

  • 4 minutes to read

The Icon Sets conditional format allows you to use predefined or custom icon sets to format different value ranges.

The image below shows a grid column whose Profit cells contain icons corresponding to numeric values.

CFIconSetsExample

Add Rules in Code

Create the IconSetFormatCondition 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:

<dxg:TableView.FormatConditions>
   <dxg:IconSetFormatCondition FieldName="Profit" PredefinedFormatName="Stars3IconSet"/>
</dxg:TableView.FormatConditions>

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

var profitFormatCondition = new IconSetFormatCondition() {
   FieldName = "Profit",
   PredefinedFormatName = "Stars3IconSet"
};
view.FormatConditions.Add(profitFormatCondition);

Define Custom Rules and Icons

The IconSetFormatCondition chooses the icon based on the minimum and maximum values from your data source. You can use the IconSetFormatCondition.MinValue and IconSetFormatCondition.MaxValue properties to define custom minimum and maximum values for the format condition:

Data Grid - Custom Icon Set Min Max Values

<dxg:TableView.FormatConditions>
   <dxg:IconSetFormatCondition FieldName="SatisfactionScore" 
                               PredefinedFormatName="Quarters5IconSet" 
                               MinValue="0" MaxValue="1"/>
</dxg:TableView.FormatConditions>
<!-- ... -->
<dxg:GridColumn FieldName="SatisfactionScore">
   <dxg:GridColumn.EditSettings>
      <dxe:TextEditSettings MaskType="Numeric"
                            Mask="p0"
                            MaskUseAsDisplayFormat="True"/>
   </dxg:GridColumn.EditSettings>
</dxg:GridColumn>

The IconSetFormat object allows you to specify custom icons and display rules:

Data Grid - Custom Icon Set Format

<dxg:IconSetFormatCondition FieldName="Profit">
   <dxg:IconSetFormatCondition.Format>
      <dx:IconSetFormat ElementThresholdType="Number">
         <dx:IconSetElement Threshold="-20" Icon="{dx:IconSet Name=RedToBlack4_1}"/>
         <dx:IconSetElement Threshold="0" Icon="{dx:IconSet Name=Stars3_2}"/>
         <dx:IconSetElement Threshold="10" Icon="{dx:IconSet Name=Stars3_1}"/>
      </dx:IconSetFormat>
   </dxg:IconSetFormatCondition.Format>
</dxg:IconSetFormatCondition>

Use the IconSetElement.Threshold property to specify the minimum value required to display the icon. The IconSetFormat.ElementThresholdType property specifies whether this value is a number or a percent relative to the minimum and maximum values in your data source.

Add Rules Using Conditional Formatting Menu

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

CFIconSetsMenu

Add 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 type in the invoked New Formatting Rule dialog.
  3. Select the Icon Sets format style.
  4. Specify the Type and Value fields. These options determine the conditional values on which cells/rows formatting is based.

    • To format cells/rows based on single column values, choose the Filed Name value in the Type field, and choose the required column field name in the Value field.
    • To specify a complex custom expression that returns a value based on several parameters (for example, several columns in a row), choose the Expression value in the Type field, and determine the required expression in the Value field using the Custom Condition Editor.
  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 Icon Style field to define the visual appearance of the applied rule. You can set the rules to determine how to display icons.

CFIconSetsManager

See Also