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

How to: Create Calculated Field

This example demonstrates how to create a calculated field in the Snap Report API.

  1. Load the document template by calling the IRichEditDocumentServer.LoadDocumentTemplate method.
  2. Call the SubDocument.BeginUpdate method to enable the document modification.
  3. Create a new CalculatedField object. Pass the name for the created field and data member to be associated with to the object’s constructor method.
  4. To associate the calculated field with the data source, use the CalculatedField.DataSourceName property.
  5. Specify the type and expression for the calculated field by setting the CalculatedField.FieldType and CalculatedField.Expression properties.
  6. Add the created CalculatedField object to the document collection of calculated fields. To do that, access the collection through the IDataSourceOwner.CalculatedFields property and call the Add method.
  7. To finalize the modification, call the SubDocument.EndUpdate method.
  8. Update the document fields by calling the FieldCollection.Update method.
Dim field As New CalculatedField("newField", "Products")
field.FieldType = DevExpress.XtraReports.UI.FieldType.Int32
field.Expression = "[UnitsInStock]*[UnitPrice]"
field.DataSourceName = "Data Source 1"