In ActiveReports, you can use an expression to set the value of a control in the report, or set conditions under which certain styles apply. You can set Microsoft Visual Basic® .NET in expressions through,
- Properties in the properties window
- Expression Editor Dialog
All expressions begin with an equal sign (=). Even the expression for a field value for a TextBox is set as follows:
=Fields!LastName.Value
Expression Editor Dialog
You can build expressions quickly using the Expression Editor dialog. This dialog allows you to choose from a number of fields available to the report as well as to a particular property. You can access the Expression Editor by selecting nearly any property of a control and choosing <Expression...> from the drop-down list.
There are seven types of fields available in the Expression Editor:
- Constants
Constants available for properties which have enumerated values such as TextDecoration or BorderStyle.
- Common Values
Run time values available to every property in every report. There are two variables in this list which come from the User collection: User ID and User Language. See Common Values for further information.
- Parameters
Parameters fields available in reports which contain report parameters. If available, you can choose a parameter from this field to retrieve the current value of the parameter.
- Fields (DataSet name)
All fields from a dataset which is linked to the report control.
- Datasets
All fields in each dataset associated with the report. However, the report retrieves only the sum or the first value of any field that is not within the current dataset scope.
- Operations
Arithmetic, comparison, concatenation, logical/bitwise, bit shift operators for creating custom expressions.
- Common Functions
Predefined Visual Basic .NET functions for which ActiveReports provides intrinsic support. See Common Functions for more information.
To create an Expression in the Expression Editor
The Expression Editor dialog comprises of two panes, Fields and Expression.
- From the Fields pane, select a field you want to use in your expression.
- Click the Replace, Insert or Append button to add the field to the Expression pane. The expression pane shows the fields in a valid expression format.
- Click OK to close the dialog.
The expression appears as the property value in the properties grid.
|
Tip: While building an expression, you can directly add the entire expression or part of it in the Expression pane of the Expression Editor. Then use the Insert or Append buttons to create a complete expression. |
Using Expressions in Reports
In the raw form, your data may not be ideally suited for display in a report. You can customize it and bring it into shape using expressions. Following are some examples of how expressions are set in different scenarios.
Concatenating Fields and Strings
You can concatenate fields with strings and with other fields. For e.g., use the following expression to get a result like Customer Name: Bossert, Lewis.
="Customer Name: " + Fields!LastName.Value + "," + Fields!FirstName.Value
Conditional Formatting
You can use expressions in properties like Color, Font, Border etc. on specific field values based on a condition, to highlight a part of data. The formula for conditional formatting is:
=iif( Fields!YourFieldName.Value operator "Value to compare", "If condition is met, use this value.", "If not, use this one."
For e.g., if you enter the following expression in the Font > FontWeight property of a textbox that displays names of people, you get the name "Denise" in bold.
=iif(Fields!FirstName.Value = "Denise", "Bold", "Normal")
Functions
You can use a number of aggregate and other functions in your expressions. ActiveReports includes a range of functions, including running value, population standard variance, standard deviation, count, minimum and maximum. For e.g., use the following expression to get a count of employees.
=Count(Fields!EmployeeID.Value, Nothing)
Displaying Expressions at Design Time
As you design the report, the full text of an expression can get very long. ActiveReports makes expressions easier to read by shortening them.
When an expression is in the form:
=Fields!<FieldName>.Value
On the design surface, you see this text inside that TextBox:
=[<FieldName>]
Double-click the TextBox to view the full expression in edit mode.
For aggregates too, when the Expression value is:
=<Aggregate>(Fields!<FieldName>.Value)
On the design surface, you see this text inside the TextBox:
=<Aggregate>([<FieldName>])
This shortened expression value is only a visual change to allow you to see the field name easily. It shows up in both the TextBox on the design surface as well as any dropdown boxes inside the dialogs.
|
Note: You can type the format as listed above for either field name values or aggregates on field names. This evaluates the full expression when the report is viewed. |
Besides the shorthand for field names, you can also type shorthand like [@Param] for parameters and [&Value] for Globals such as [&PageNumber] on the design surface. Please note that you cannot use shorthand in the Expression Editor.
See Also