Use the TableView.FormatConditions / TreeListView.FormatConditions property to define conditional formatting rules:
Xaml |
<dxg:GridControl x:Name="grid">
<dxg:GridControl.View>
<dxg:TableView>
<dxg:TableView.FormatConditions>
<dxg:TopBottomRuleFormatCondition FieldName="UnitPrice" Rule="TopPercent"
Threshold="10" PredefinedFormatName="LightRedFillWithDarkRedText" />
<dxg:TopBottomRuleFormatCondition FieldName="UnitPrice" Rule="BelowAverage"
PredefinedFormatName="YellowFillWithDarkYellowText" />
<dxg:FormatCondition FieldName="Quantity" ValueRule="LessOrEqual"
Value1="5" PredefinedFormatName="BoldText" />
<dxg:FormatCondition FieldName="Discount" ValueRule="Greater"
Value1="0" PredefinedFormatName="GreenFillWithDarkGreenText" ApplyToRow="True" />
<dxg:FormatCondition Expression="Contains([Country], 'Sw')"
PredefinedFormatName="ItalicText" ApplyToRow="True" />
</dxg:TableView.FormatConditions>
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
|
Filter Editor
Select conditional formatting filters in the Filter Editor:

Excel-style Drop-down Filter
Select conditional formatting filters in the Excel-style Drop-down Filter:

Format Condition Filter Element
Select conditional formatting filters in the FormatConditionFilterElement:

Add a FormatConditionFilterElement to the markup and specify the target GridControl and a column. The filter element lists all available conditional formats for the specified column:
Xaml |
<dxg:GridControl x:Name="grid" ... />
<dxfui:FormatConditionFilterElement FieldName="UnitPrice" Context="{Binding FilteringContext, ElementName=grid}"/>
|
In Code
Specify a filter string or filter criteria in code. The GridControl finds a corresponding conditional format rule and applies a filter that is based on this rule.
Note
If you specified a conditional formatting filter and then decided to change a conditional format on which the filter is based, the GridControl does not apply the filter. Change the filter to make it correspond to the changed conditional format.
The code sample below applies a filter that is based on the
<dxg:TopBottomRuleFormatCondition FieldName="UnitPrice" Rule="BelowAverage" PredefinedFormatName="YellowFillWithDarkYellowText" />
conditional format:
C# |
grid.FilterString = "[@BelowAverage]([UnitPrice])";
grid.FilterCriteria = new FunctionOperator("@BelowAverage", new OperandProperty("UnitPrice"));
|
VB |
grid.FilterString = "[@BelowAverage]([UnitPrice])"
grid.FilterCriteria = New FunctionOperator("@BelowAverage", New OperandProperty("UnitPrice"))
|
The following code sample applies a filter that is based on the
<dxg:FormatCondition FieldName="Quantity" ValueRule="LessOrEqual" Value1="5" PredefinedFormatName="BoldText" />
conditional format:
C# |
grid.FilterString = "[@LessOrEqual]([Quantity], 5)";
grid.FilterCriteria = new FunctionOperator("@LessOrEqual", new OperandProperty("Quantity"), new OperandValue(5));
|
VB |
grid.FilterString = "[@TopPercent]([UnitPrice], 10)"
grid.FilterString = "[@BelowAverage]([UnitPrice])"
grid.FilterString = "[@LessOrEqual]([Quantity], 5)"
grid.FilterCriteria = New FunctionOperator("@TopPercent", New OperandProperty("UnitPrice"), New OperandValue(10))
grid.FilterCriteria = New FunctionOperator("@BelowAverage", New OperandProperty("UnitPrice"))
grid.FilterCriteria = New FunctionOperator("@LessOrEqual", New OperandProperty("Quantity"), New OperandValue(5))
|
The following code samples demonstrate how to apply conditional formatting filters:
C# |
grid.FilterString = "[@Equal]([Profit], 10)";
grid.FilterString = "[@NotEqual]([Profit], 10)";
grid.FilterString = "[@Greater]([Profit], 10)";
grid.FilterString = "[@GreaterOrEqual]([Profit], 10)";
grid.FilterString = "[@Less]([Profit], 10)";
grid.FilterString = "[@LessOrEqual]([Profit], 10)";
grid.FilterString = "[@Between]([Profit], 10, 20)";
grid.FilterString = "[@NotBetween]([Profit], 10, 20)";
grid.FilterString = "[@Expression]([Profit], '[Profit]=5')";
grid.FilterString = "[@TopItems]([Profit], 10)";
grid.FilterString = "[@TopPercent]([Profit], 10)";
grid.FilterString = "[@BottomItems]([Profit], 10)";
grid.FilterString = "[@BottomPercent]([Profit], 10)";
grid.FilterString = "[@AboveAverage]([Profit])";
grid.FilterString = "[@BelowAverage]([Profit])";
grid.FilterString = "[@Unique]([Profit])";
grid.FilterString = "[@Duplicate]([Profit])";
|
VB |
grid.FilterString = "[@Equal]([Profit], 10)"
grid.FilterString = "[@NotEqual]([Profit], 10)"
grid.FilterString = "[@Greater]([Profit], 10)"
grid.FilterString = "[@GreaterOrEqual]([Profit], 10)"
grid.FilterString = "[@Less]([Profit], 10)"
grid.FilterString = "[@LessOrEqual]([Profit], 10)"
grid.FilterString = "[@Between]([Profit], 10, 20)"
grid.FilterString = "[@NotBetween]([Profit], 10, 20)"
grid.FilterString = "[@Expression]([Profit], '[Profit]=5')"
grid.FilterString = "[@TopItems]([Profit], 10)"
grid.FilterString = "[@TopPercent]([Profit], 10)"
grid.FilterString = "[@BottomItems]([Profit], 10)"
grid.FilterString = "[@BottomPercent]([Profit], 10)"
grid.FilterString = "[@AboveAverage]([Profit])"
grid.FilterString = "[@BelowAverage]([Profit])"
grid.FilterString = "[@Unique]([Profit])"
grid.FilterString = "[@Duplicate]([Profit])"
|
If a conditional format is applied to the entire row (see FormatConditionBase.ApplyToRow), you should specify a column to which you want to apply a conditional formatting filter.
The code sample below applies a filter that is based on the
<dxg:FormatCondition FieldName="Discount" ValueRule="Greater" Value1="0" PredefinedFormatName="GreenFillWithDarkGreenText" ApplyToRow="True" />
conditional format to the Country column. The first parameter is a filtered column's name and the second is a conditional format's field name:
C# |
grid.FilterString = "[@Greater]([Country], [Discount], 0)";
grid.FilterCriteria = new FunctionOperator("@Greater", new OperandProperty("Country"), new OperandProperty("Discount"), new OperandValue(0));
|
VB |
grid.FilterString = "[@Greater]([Country], [Discount], 0)"
grid.FilterCriteria = New FunctionOperator("@Greater", New OperandProperty("Country"), New OperandProperty("Discount"), New OperandValue(0))
|

If an expression condition is applied to the entire row and it does not have a field name, specify []
as the second parameter.
The code sample below applies a filter that is based on the
<dxg:FormatCondition Expression="Contains([Country], 'Sw')" PredefinedFormatName="ItalicText" ApplyToRow="True" />
conditional format to the Country column:
C# |
grid.FilterString = "[@Expression]([Country], [], 'Contains([Country], ''Sw'')')";
|
VB |
grid.FilterString = "[@Expression]([Country], [], 'Contains([Country], ''Sw'')')"
|
