The requested page is not available for the requested platform. You are viewing the content for Default platform.

CalculatedField.DataSource Property

Specifies the data source, associated with the calculated field.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.dll

Declaration

public override object DataSource { get; set; }
Public Overrides Property DataSource As Object

Property Value

Type Description
Object

A Object representing a calculated field's data source.

Remarks

To allow a calculated field to get access to data fields available in a data source, specify the DataSource and CalculatedField.DataMember properties. Following that, you can refer to these data fields from within the calculated field's CalculatedField.Expression.

When a calculated field's DataSource is empty, the field tries to obtain it from its parent (i.e., the XtraReport object to which the calculated field belongs).

To learn more, see Calculated Fields Overview.

Examples

This example demonstrates how a calculated field can be created at runtime and bound to a control's XRControl.Text property.

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Configuration;
// ...

private void button1_Click(object sender, EventArgs e) {

    // Create a report.
    XtraReport1 report = new XtraReport1();

    // Create a calculated field 
    // and add it to the report's collection.
    CalculatedField calcField = new CalculatedField();
    report.CalculatedFields.Add(calcField);

    // Define the calculated field's properties.
    calcField.DataSource = report.DataSource;
    calcField.DataMember = report.DataMember;
    calcField.FieldType = FieldType.Double;
    calcField.DisplayName = "Calculated Field";
    calcField.Name = "myField";
    calcField.Expression = "[UnitPrice] * [UnitsInStock]";

    // Bind a label's Text property to the calculated field.
    report.FindControl("xrlabel2", true).DataBindings.Add("Text", null, "Order Details.myField");

    // Bind a label's Text property to the calculated field 
    // depending on the report's data binding mode.
    if (Settings.Default.UserDesignerOptions.DataBindingMode == DataBindingMode.Bindings)
        report.FindControl("xrlabel3", true).DataBindings.Add("Text", null, "Products.myField", "{0:c2}");
    else report.FindControl("xrlabel3", true).ExpressionBindings.Add(
        new ExpressionBinding("BeforePrint", "Text", "FormatString('{0:c2}', [myField])"));

    // Display the report.
    ReportPrintTool printTool = new ReportPrintTool(report);
    printTool.ShowPreviewDialog();
}
See Also