Skip to main content

CalculatedField.DataSource Property


Deserializing a report layout from untrusted resources may create security issues. Serializable System.Object properties that contain custom type values are not (de)serialized automatically. Review the following help topic for information on how to (de)serialize custom type values: Reporting — Safe Deserialization.

Specifies the data source, associated with the calculated field.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.1.dll

NuGet Package: DevExpress.Reporting.Core


public override object DataSource { get; set; }

Property Value

Type Description

A Object representing a calculated field’s data source.


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.


This example demonstrates how to create a calculated field at runtime, and bind the field to the report control’s Text property.

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();

// 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])"

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


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