Specify a Control's Binding Expression

  • 2 minutes to read

Specify a control's binding expression to bind report controls to a report's data source field(s). An expression can point to a data source field(s), calculated field(s), or report parameter(s), or combine static and dynamic content (for instance, append a text prefix or postfix to a value obtained from a database).

This topic describes the methods to specify a binding expression.

Design Time

After you bind a report to data, the Field List displays the data source hierarchy and gives access to the available data fields.

  • Use the Field List to bind report controls to data.

    • Drop a data field onto the report surface to create a new report control bound to this field.

      DesignTimeFeatures - FieldList2.png

    • Drop a data field onto a control to bind this control to the dropped field.

      DesignTimeFeatures - FieldList3.png

    See the Field List topic for more information.

  • Specify a control's binding expression directly.

    • Click a property's ellipsis button and specify an expression in the invoked Expression Editor.

      label-expression-editor-complex-binding

    • Switch to the Expressions tab in the Properties panel to access the properties where you can specify a binding expression.

      Properties Panel - Expressions Tab

After you bind a report control to data, use the Format String property to format the control's value.

Runtime

You can specify a report control's binding expression at runtime. Create an ExpressionBinding object, specify its settings, and add the created object to the control's ExpressionBindings collection. 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.

The following code demonstrates how to specify an expression for a label's Text property:

using DevExpress.XtraReports.UI;

public XtraReport1() {
    // ...
    ExpressionBinding expressionBinding = new ExpressionBinding("BeforePrint", "Text", "[UnitPrice]*[UnitsInStock]");
    xrLabel1.ExpressionBindings.Add(expressionBinding);
}
See Also