Skip to main content
A newer version of this page is available. .

Conditionally Changing a Band's Visibility

  • 2 minutes to read

This document describes how to change a report band’s visibility in Print Preview based on a specific logical condition.

Note

You can use this approach to conditionally changing a band’s visibility when the UserDesignerOptions.DataBindingMode is set to DataBindingMode.Expressions or DataBindingMode.ExpressionsAdvanced.

See Conditionally Changing a Band’s Visibility to learn about the legacy approach to solving this task.

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

After you bound your report to data and provided content to the report’s detail band, the report can display an additional header based on the selected filtering criteria.

  • Right-click the report’s surface and add a report header.

    add-report-header

  • Right-click the report header area and create a sub-band, which is the report header’s functional copy.

    add-sub-band-report-header

  • Add two labels to the created bands, providing content for the two report header copies.

    sub-band-report-header

  • Select the sub-band and switch to the Visual Studio property grid. Switch to its Expressions section and click the Visible property’s ellipsis button (you can find it under the BeforePrint event’s category if you are using the ExpressionsAdvanced binding mode).

    sub-band-expression-visible

  • This invokes the Summary Expression Editor where you can specify the required summary function. For example:

    sub-band-expression-editor-visible

    The expression above makes the Visible property return True or False values based on the Discontinued data field’s value.

  • Switch to the Field List, right-click the Parameters section and add a new report parameter.

    field-list-add-parameter

  • Specify the parameter’s description displayed in Print Preview and set its type to Boolean.

    parameter-boolean-no

  • Invoke the report’s smart tag and click the XtraReportBase.FilterString property’s ellipsis button.

    report-smart-tag-filter-string

  • This invokes the FilterString Editor where you can specify the required filter criteria and a reference to the created parameter.

    filter-string-editor-parameter-evaluation

When switching to Print Preview, the report can display the sub-band by selecting the corresponding parameter value:

toggle-band-visibility-preview-result