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

Conditionally Change a Band's Visibility

This document describes how to toggle the visibility of a report band in Print Preview based on a certain logical condition.


This approach to conditionally changing a band's visibility applies when the UserDesignerOptions.DataBindingMode is set to DataBindingMode.Bindings.

See Conditionally Change a Band's Visibility 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 the sub-band by selecting the corresponding parameter value in Print Preview:


Do the following to make the report display an additional header based on the selected filtering criteria:

  1. To create a table report in this tutorial, start with a report that is bound to the CategoryProducts view of the sample Northwind database (the nwind.mdb file included with the XtraReports installation). To learn more about binding a report to a data source, see Provide Data to Reports.
  2. Group the report data by the CategoryProduct field. Then, drop the ProductName field from the Field List onto the report's Detail band to create the report's main content.

    How to - GroupData_3

  3. Add a SubBand to the Report Header band. To do this, right-click the Report Header band and choose Add Sub-Band in the invoked dialog.


  4. Drop XRLabel controls onto the Report Header band and its sub-band and specify the labels' text as shown below.


  5. Select the created sub-band and click its smart tag. In the invoked 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 - ConditionallySuppressControls_0a

  6. 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 - ConditionallySuppressControls_1

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

  7. In this editor, define a Boolean expression for the rule (e.g., [Discontinued] == False). This means that the Discontinued data field should be false for the appropriate control to be hidden.

    How to - ConditionallySuppressControls_2

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

  8. Now, in the Formatting Rules Editor, you can see the created rule (named formattingRule1), which should be moved to the list of active rules at the right using the arrow buttons in the middle of the dialog.

    How to - ConditionallyFilterData_3

    It is also possible to customize the precedence of formatting rules by using the up and down arrow buttons at the right of the dialog. The rules are applied in the same order they are on the list, and the last rule on the list has the highest priority.

  9. Switch to the Field List, right-click the Parameters section, and choose Add Parameter. In the invoked window, set the name of the created parameter and choose its type.


  10. Next, click the smart tag of your report, and click the ellipsis button for the XtraReportBase.FilterString property.

    In the invoked FilterString Editor, construct an expression where the Discounted data field is compared with the parameterDiscounted parameter. To access the parameter, click the icon on the right until it turns into a question mark.