All docs
V20.2
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Conditional Formatting Filters

  • 4 minutes to read

The GridControl allows you to specify Conditional Formatting rules and apply filters based on these rules:

Specify Conditional Formatting Rules

Use the TableView.FormatConditions / TreeListView.FormatConditions property to define conditional formatting rules:

<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>

Apply Conditional Formatting Filters

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:

<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:

grid.FilterString = "[@BelowAverage]([UnitPrice])";
// or
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:

grid.FilterString = "[@LessOrEqual]([Quantity], 5)";
// or
grid.FilterCriteria = new FunctionOperator("@LessOrEqual", new OperandProperty("Quantity"), new OperandValue(5));
TIP

To build a filter string, you can apply a filter to the GridControl's in UI, and then obtain the filter string with the DataControlBase.FilterString property.

More Examples

The following code samples demonstrate how to apply conditional formatting filters:

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, 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:

grid.FilterString = "[@Greater]([Country], [Discount], 0)";
// or
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:

grid.FilterString = "[@Expression]([Country], [], 'Contains([Country], ''Sw'')')";

Limitations