wpf-118907-controls-and-libraries-data-grid-conditional-formatting-conditional-formats-formatting-top-and-bottom-values.md
The Top-Bottom conditional format allows you to highlight a specific number of top/bottom values. You can specify this number as an absolute or percent value.
The image below shows the grid column whose top 20 Profit values are green.
This topic consists of the following sections:
Create the TopBottomRuleFormatCondition class instance and specify the following settings to create a conditional format in code:
Specify the rule type using the TopBottomRuleFormatCondition.Rule property.
Specify the required rank value using the TopBottomRuleFormatCondition.Threshold property.
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 TopBottomRuleFormatCondition 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:TopBottomRuleFormatCondition Rule="TopItems" Threshold="20" FieldName="Profit" PredefinedFormatName="GreenFillWithDarkGreenText" />
</dxg:TableView.FormatConditions>
The code sample below illustrates how to define the same conditional format in code-behind:
var profitFormatCondition = new TopBottomRuleFormatCondition() {
Rule = TopBottomRule.TopItems,
Threshold = 20,
FieldName = "Profit",
PredefinedFormatName = "GreenFillWithDarkGreenText"
};
view.FormatConditions.Add(profitFormatCondition);
Dim profitFormatCondition = New TopBottomRuleFormatCondition() With {
.Rule = TopBottomRule.TopItems,
.Threshold = 20,
.FieldName = "Profit",
.PredefinedFormatName = "GreenFillWithDarkGreenText"
}
view.FormatConditions.Add(profitFormatCondition)
See Also