wpf-118924-controls-and-libraries-data-grid-conditional-formatting-conditional-formats-formatting-values-using-data-bars.md
The Data Bars conditional format allows you to visualize values using bars.
The image below shows the grid column whose Profit cells contain data bars corresponding to cell values.
This topic consists of the following sections:
Create the DataBarFormatCondition class instance and specify the following settings to create a conditional format in code:
Use the FormatConditionBase.FieldName property to specify the column’s field name to which the conditional format should apply.
Formatting cells/rows are based on single column values by default. Use the FormatConditionBase.Expression property to specify a complex custom expression that returns a value based on several parameters (for example, several columns in a row).
Specify the target cells’ formatting:
Set a selective expression using the IndicatorFormatConditionBase.SelectiveExpression property if it is necessary to select data records to which the rule should apply.
Add the resulting DataBarFormatCondition 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:DataBarFormatCondition FieldName="Profit" PredefinedFormatName="BlueGradientDataBar"/>
</dxg:TableView.FormatConditions>
The code sample below illustrates how to define the same conditional format in code-behind:
var profitFormatCondition = new DataBarFormatCondition() {
FieldName = "Profit",
PredefinedFormatName = "BlueGradientDataBar"
};
view.FormatConditions.Add(profitFormatCondition);
Dim profitFormatCondition = New DataBarFormatCondition() With {
.FieldName = "Profit",
.PredefinedFormatName = "BlueGradientDataBar"
}
view.FormatConditions.Add(profitFormatCondition)
Click the New Rule… in the Conditional Formatting Rules Manager.
Select the Format all cells based on their values rule in the invoked New Formatting Rule dialog.
Select the Data Bar format style.
Specify the Type and Value fields. These options determine the conditional values on which formatting of cells/rows is based.
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 cell values’ maximum and minimum values by default.
Specify the Positive Bar Appearance and Negative Bar Appearance fields to define the visual appearance of the applied rule.
See Also