wpf-114001-controls-and-libraries-data-grid-conditional-formatting-conditional-formats-formatting-values-using-comparison-rules.md
The following conditional formats allow you to format cells comparing cell values with static values:
Refer to the Formatting Date-Time Values topic to learn how to highlight date-time values that fall into a specified interval. The Formatting Values Using Custom Conditions topic describes how to use custom conditions.
This topic consists of the following sections:
Create the FormatCondition class instance and specify the following settings to create a conditional format in code:
Specify the comparison logic:
Use the FormatConditionBase.FieldName property to specify the column’s field name to which to apply the conditional format.
Specify the target cells’ formatting:
Add the resulting FormatCondition instance to the TableView.FormatConditions (or TreeListView.FormatConditions) collection.
The following code sample illustrates how to define a conditional format in markup:
<dxg:TableView.FormatConditions>
<dxg:FormatCondition ValueRule="Greater" Value1="10000000" FieldName="Profit" PredefinedFormatName="LightRedFillWithDarkRedText" />
</dxg:TableView.FormatConditions>
The code sample below illustrates how to define the same conditional format in code-behind:
var profitFormatCondition = new FormatCondition() {
ValueRule = ConditionRule.Greater,
Value1 = 10000000,
FieldName = "Profit",
PredefinedFormatName = "LightRedFillWithDarkRedText"
};
view.FormatConditions.Add(profitFormatCondition);
Dim profitFormatCondition = New FormatCondition() With {
.ValueRule = ConditionRule.Greater,
.Value1 = 10000000,
.FieldName = "Profit",
.PredefinedFormatName = "LightRedFillWithDarkRedText"
}
view.FormatConditions.Add(profitFormatCondition)
Click New Rule… in the Conditional Formatting Rules Manager.
Select the Format only cells that contain rule in the invoked New Formatting Rule dialog.
Select the required content type:
Choose the conditional format, and specify the required value(s) or text.
To define the visual appearance of the applied rule, click the Format button, and specify the required settings in the invoked Format Cells dialog window. See the Format Cells Dialog Window section of the Conditional Formatting Rules Manager topic to learn more.
See Also