Back to Devexpress

CalculatedField.DataMember Property

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-calculatedfield-62454940.md

latest5.5 KB
Original Source

CalculatedField.DataMember Property

Specifies the data member of the calculated field.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public override string DataMember { get; set; }
vb
Public Overrides Property DataMember As String

Property Value

TypeDescription
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 to create a calculated field at runtime, and bind the field to the report control’s Text property.

csharp
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Configuration;
// ...
// 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);

// Specify 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 the label's Text property to the calculated field.
report.FindControl("xrlabel3", true).ExpressionBindings
            .Add(new ExpressionBinding() {
                EventName = "BeforePrint",
                PropertyName = "Text",
                Expression = "FormatString('{0:c2}', [myField])"
            });
vb
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Configuration
' ...
' Create a report.
Dim report As New XtraReport1()

' Create a calculated field 
' and add it to the report's collection.
Dim calcField As 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("xrlabel3", True).ExpressionBindings.Add(New ExpressionBinding("BeforePrint", "Text", "FormatString('{0:c2}', [myField])"))

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.

reporting-winforms-calculated-field-runtime/CS/UsingCalculatedFields/Form1.cs#L24

csharp
calcField.DataSource = report.DataSource;
calcField.DataMember = report.DataMember;
calcField.FieldType = FieldType.Double;

reporting-winforms-calculated-field-runtime/VB/UsingCalculatedFields/Form1.vb#L27

vb
calcField.DataSource = report.DataSource
calcField.DataMember = report.DataMember
calcField.FieldType = FieldType.Double

See Also

DataSource

Calculated Fields

CalculatedField Class

CalculatedField Members

DevExpress.XtraReports.UI Namespace