Back to Devexpress

Conditionally Hide Controls

xtrareports-119439-feature-guide-to-devexpress-reports-use-expressions-expressions-tasks-and-solutions-conditionally-suppress-controls.md

latest3.7 KB
Original Source

Conditionally Hide Controls

  • Feb 18, 2026
  • 2 minutes to read

This document describes how to hide a report control based on a certain logical condition when the user views/prints/exports a report. To do this, set an expression for the Visible property of the control.

The report in this topic has a column that displays a check box when the Discontinued data field value is True.

Follow the steps below to conditionally hide controls:

  1. Drag the Discontinued data field from the Field List onto the report to create the Checkbox control bound to the Discontinued field:

  2. Set the XRCheckBox.GlyphOptions.Alignment property to Center:

  3. Select the control, and click the f button to invoke the Expression Editor. Enter the following expression for the Visible property:

  4. Switch to preview mode to see the result:

Hide a Control at Runtime

Specify an Expression for the Visible Property

At runtime, you can specify an expression as described earlier:

csharp
using DevExpress.XtraReports.UI;

public XtraReport1() {
    // ...
    ExpressionBinding expressionBinding = new ExpressionBinding("BeforePrint", "Visible", "[Discontinued]");
    xrCheckBox1.ExpressionBindings.Add(expressionBinding);
}
vb
Imports DevExpress.XtraReports.UI

Public Sub New()
    ' ...
    Dim expressionBinding As New ExpressionBinding("BeforePrint", "Visibles", "[Discontinued]")
    xrCheckBox1.ExpressionBindings.Add(expressionBinding)
End Sub

Review the following help topic for more information: Create Expression at Runtime.

Handle the Control’s BeforePrint Event

Set the event argument’s Cancel property to True in the control’s BeforePrint event handler:

csharp
private void xrCheckBox1_BeforePrint(object sender, CancelEventArgs e) {
    e.Cancel = !Convert.ToBoolean(((XRControl)sender).Report.GetCurrentColumnValue("Discontinued"));
}
vb
Private Sub XrCheckBox1_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles XrCheckBox1.BeforePrint
    e.Cancel = Not Convert.ToBoolean(CType(sender, XRControl).Report.GetCurrentColumnValue("Discontinued"))
End Sub

How to Avoid Empty Space When a Control is Hidden

To hide a control without leaving blank space in the report, set the properties as follows:

CanShrinkTrueText

Empty string (‘’). To hide a control based on a condition, specify the following expression as the Text expression binding that conditionally sets its value to an empty string:

Iif(YOUR_CONDITION, '', TEXT OR [YOUR_DATA_FIELD])

VisibleTrue (default value)