Skip to main content
A newer version of this page is available. .

CalculatedField.DataMember Property

Specifies the data member of the calculated field.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.2.dll

NuGet Packages: DevExpress.Reporting.Core, DevExpress.WindowsDesktop.Reporting.Core

Declaration

public override string DataMember { get; set; }

Property Value

Type Description
String

A String containing a calculated field’s data member.

Remarks

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

To learn more, see Calculated Fields Overview.

Example

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.
    new ExpressionBinding("BeforePrint", "Text", "FormatString('{0:c2}', [myField])"));

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DataMember property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also