Skip to main content
A newer version of this page is available. .

Creating Conditional Formatting Rules

  • 4 minutes to read

This topic describes how to create conditional formatting rules.

Creating Conditional Formatting Rules at Design Time

The GridControl provides the following ways of creating conditional formatting rules at design time:

Adding Rules Using Conditional Formatting Menu

The Conditional Formatting Menu allows you to quickly create conditional formatting rules using predefined settings.

In the design view, right-click a column to which you want to add a conditional formatting rule and select Conditional Formatting to invoke the conditional formatting menu.

ConditonalFormattingMenuOpeningInDesignTime

Note

Specify the type of records contained in the data source using the DataControlBase.DesignTimeDataObjectType property to make the conditional formatting menu correctly work.

Adding Rules Using Conditional Formatting Rules Manager

The Conditional Formatting Rules Manager allows you to create conditional formatting rules with custom settings. You can view and edit all conditional formatting rules currently applied to the grid’s view.

Use the following ways to invoke the conditional formatting rules manager:

  • In the design view, right-click a column and select Conditional Formatting | Manage Rules.

    ConditionalFormattingRulesManagerOpeningInDesignTime0

  • In the design view, right-click the GridControl’s smart tag menu and select Manage Conditional Formatting Rules.

    ConditionalFormattingRulesManagerOpeningInDesignTime1

  • In the design view, right-click the GridColumn’s smart tag menu and select Manage Conditional Formatting Rules.

    ConditionalFormattingRulesManagerOpeningInDesignTime2

Note

Specify the type of records contained in the data source using the DataControlBase.DesignTimeDataObjectType property to make the conditional formatting rules manager correctly work.

Creating Conditional Formatting Rules in Code

The TableView.FormatConditions (or TreeListView.FormatConditions) collection stores conditional formatting rules applied to the grid’s view.

The following code sample illustrates how to define a conditional formatting rule in markup. See the How to: Apply Conditional Formatting example to learn more.

<dxg:TableView.FormatConditions>
   <dxg:DataBarFormatCondition FieldName="Visits" PredefinedFormatName="GreenGradientDataBar" />
</dxg:TableView.FormatConditions>

The code sample below illustrates how to define the same conditional formatting rule in code-behind. See the How to: Apply Conditional Formatting in Code-Behind example to learn more.

var visitsDataBar = new DataBarFormatCondition() {
   FieldName = "Visits",
   PredefinedFormatName = "GreenGradientDataBar"
};
view.FormatConditions.Add(visitsDataBar);

Use the following methods to remove conditional formatting rules:

Creating Conditional Formatting Rules at Runtime

The GridControl provides the following ways of creating conditional formatting rules at runtime:

Adding Rules Using Conditional Formatting Menu

The Conditional Formatting Menu allows you to quickly create conditional formatting rules using predefined settings.

Right-click a column to which you want to add a conditional formatting rule, and select Conditional Formatting in the displayed context menu to invoke the conditional formatting menu.

ConditionalFormattingMenuOpening

You can enable the conditional formatting menu as follows:

Adding Rules Using Conditional Formatting Rules Manager

The Conditional Formatting Rules Manager allows you to create conditional formatting rules with custom settings. You can view and edit all conditional formatting rules currently applied to the grid’s view.

Click the Manage Rule item in the Conditional Formatting Menu to invoke the conditional formatting rules manager.

ConditionalFormattingManagerOpening

Set the TableView.AllowConditionalFormattingManager (or TreeListView.AllowConditionalFormattingManager) property to true to enable the manager at runtime.

See Also