The requested page is not available for the requested platform. You are viewing the content for Default platform.

Conditionally Filter Report Data

  • 2 min to read

This tutorial demonstrates how to filter a report's data based on a certain condition.

Note

This approach to filtering data applies when the UserDesignerOptions.DataBindingMode is set to DataBindingMode.Bindings.

See Conditionally Filter Report Data to learn about the alternative approach to solving this task.

See Data Binding Modes to learn more about the available binding modes.

The report created in this tutorial displays products having the price exceeding $50:

How to - ConditionallyFilterData

Do the following to conditionally filter report data:

  1. To create a table report in this tutorial, start with a report that is bound to the "Products" table of the sample Northwind database (the nwind.mdb file included in the XtraReports installation). To learn more about binding a report to a data source, see Provide Data to Reports.
  2. Drag the ProductName and UnitPrice fields from the Field List window, and drop them onto the report's Detail band.

    HowTo - FilterDataReportLevel_0

  3. Click the Detail band's smart tag, and in its actions list, click the ellipsis button for the XRControl.FormattingRules property.

    Then, in the invoked Formatting Rules Editor, click the Edit Rule Sheet... button.

    How to - ConditionallyFilterData_0

  4. In the invoked Formatting Rule Sheet Editor, click Buttons_Plus, to create a new formatting rule. For this rule, set the Visible property to false.

    How to - ConditionallyFilterData_1

    Next, locate the FormattingRule.Condition property and click its ellipsis button. The Condition Editor will appear.

  5. In this editor, define a Boolean expression for the rule (e.g., [UnitPrice] <= 50). The [UnitPrice] <= 50 expression means that the UnitPrice data field should be less than or equal to 50 for the appropriate data row to be hidden.

    How to - ConditionallyFilterData_2

    Click OK to save the changes and close the dialog. Then click Close to quit the Formatting Rule Sheet Editor.

  6. In the Formatting Rules Editor, you can see the created rule (called formattingRule1), which should be moved to the list of active rules on the right using the arrow buttons in the center of the dialog box.

    How to - ConditionallyFilterData_3

    In this editor, you can also customize the precedence of formatting rules using the up and down arrow buttons on the right of the dialog box. The rules are applied in the same order that they appear in the list, and the last rule in the list has the highest priority.