Skip to main content

Data Binding Modes

  • 4 minutes to read

You can use the Report Designer in Expressions or ExpressionsAdvanced data binding mode.

Note

If your reports rely on the legacy Bindings mode, consider converting the reports to employ Expressions or Expressions Advanced mode instead. Refer to the following topic for more information: Migrate from Legacy Data Bindings to Expressions.

Expressions Mode

This default binding mode enables you to specify expressions that include data fields, report parameters, or functions. You can also use expressions to calculate summaries of any complexity or conditionally hide controls or change their appearance.

All expressions are evaluated when a control’s BeforePrint event occurs.

Specify an Expression

Invoke the Expression Editor to enter or modify an expression. You can switch the Properties panel to the Expressions tab to access the properties that you can bind to expressions, and click the ellipsis button next to the property:

property-grid-expression-tab

Alternatively, click the expression button (with an f symbol) displayed next to the selected control:

The f Button Near the Control

The Expression Editor is invoked. You can choose a property and enter an expression:

expressions-label-example

ExpressionsAdvanced Mode

This mode enables you to specify expressions that are evaluated when the BeforePrint or PrintOnPage events occur.

property-grid-expression-advanced-tab

The Expression Editor allows you to use event argument values in expressions. Event arguments are available in the Variables section.

Expressions Tab - Expressions Advanced Mode

Expressions Calculated in the BeforePrint Event

You can use data fields from the data source queries:

Expression Editor for the BeforePrint event

Event arguments include the number of rows within the data source and the current row index.

Expression Editor for the BeforePrint Event - Arguments

Expressions Calculated in the PrintOnPage Event

In the PrintOnPage event handler, the data source fields are not available (the Fields node in the Expression Editor includes only report parameters), because the data processing stage is already finished when this event occurs.

Event arguments include the number of pages in the report and the current page index. You can use these variables to conditionally hide controls on certain pages. The following expression, specified for the control’s Visible property, prints the control on all pages except the first page:

![Arguments.PageIndex] == 0

Expression Editor for the PrintOnPage event

Note

The BeforePrint and PrintOnPage events occur at runtime regardless of data binding mode.

How to Specify Binding Mode

Design Time

Use the Data Binding Mode property in the Report Designer Options dialog to select the binding mode for your reports and controls.

report-designer-options-dialog

Reload the Report Designer after you change the binding mode.

Runtime

In code, specify the static UserDesignerOptions.DataBindingMode property to select the binding mode for your reports.

static class Program {
    static void Main() {
        DevExpress.XtraReports.Configuration.Settings.Default.UserDesignerOptions.DataBindingMode = 
            DevExpress.XtraReports.UI.DataBindingMode.ExpressionsAdvanced;
        // ...
    }
}

You can specify an expression that is rendered within the BeforePrint or PrintOnPage events. Specify the following properties in the created object:

  • EventName - specifies the event handler that evaluates the expression.
  • PropertyName - specifies the property to which to apply a binding expression.
  • Expression - specifies the binding expression.
// Create a label control.
XRLabel label = new XRLabel();
// Specify an expression that sets the label's Text to the current date. The expression is rendered within the BeforePrint event.
XRLabel.ExpressionBindings.Add (new ExpressionBinding("Text", "TODAY()"));
// Specify an expression that is rendered within the PrintOnPage event.
XRLabel.ExpressionBindings.Add (new ExpressionBinding("PrintOnPage","Font.Bold","true"));

Limitations

  • The Expression bindings mode is not supported for the following controls:

    Although bindings are available, they are not processed and have no effect. To solve your task, handle the report’s BeforePrint event.

See Also