Data Binding Modes
- 3 minutes to read
You can switch the Report Designer to the following data binding modes:
Expressions is the default binding mode.
This mode enables you to specify complex expressions that include two or more data fields, report parameters, or functions. You can also use expressions to calculate summaries of any complexity or conditionally shape your data.
Switch the Properties panel to the Expressions tab to access the properties where you can specify an expression.
Click a property’s ellipsis button to invoke the Expression Editor. The Expression Editor allows you to use functions, access report bands and controls, and reference data source values in the constructed expression.
ExpressionsAdvanced is the advanced Expression mode.
In this mode, the Report Designer enables you to specify an expression that is evaluated within a control’s specific event.
The Expression Editor allows you to use event argument values in the constructed expressions. Event arguments are available in the Variables section.
In the BeforePrint event, you can use data fields from all queries in the data source.
In the PrintOnPage event, data source fields are not available because data was fetched when this event occurs. You can use the event arguments that are available in the Variables section.
At runtime, the BeforePrint and PrintOnPage events are fired regardless of the data binding mode.
Note
If you have the legacy Bindings mode specified in your reports, consider converting the reports to Expressions or Expressions Advanced. See Migrate from Legacy Data Bindings to Expressions for more information.
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.
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 apply a binding expression to.
- 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"));