Data Binding Modes

  • 3 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 shape your data.

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

Switch the Properties panel to the Expressions tab to access the properties that you can bind to expressions.

property-grid-expression-tab

Click a property’s ellipsis button to construct an expression in the invoked Expression Editor.

expressions-page-break

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 that are Evaluated During the BeforePrint Event

You can use data fields from the data source’s queries.

Expression Editor for the BeforePrint event

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

Expression Editor for the BeforePrint Event - Arguments

Expressions that are Evaluated During the PrintOnPage Event

Data source fields are not available (the Fields node in the Expression Editor is empty) because the data processing stage is finished when this event occurs.

Event arguments include the number of pages in the report and the current page. You can use these variables to conditionally hide controls on specific pages. For instance, specify the following expression for a control’s Visible property to print this control only on the first page:

![Arguments.PageIndex] == 0

Expression Editor for the PrintOnPage event

At runtime, the BeforePrint and PrintOnPage events are fired regardless of the data binding mode.

Set 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 - defines 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"));
See Also