You are currently reviewing an older revision of this page.
Data can be read from the project database and displayed on reports by simply dragging a data field onto the report template in Report Template Designer. It is possible to manipulate data from the database or otherwise before it is displayed on the report by using scripts in Report Template Designer. This document describes how to use OnBeforePrint scripts as a reference for other articles. See the articles listed in the See Also section for specific OnBeforePrint script examples.
OnBeforePrint scripts "overwrite" the contents of the table cell or label they are applied to, even if a data field is bound to the cell or label.
Open a project page using Project Manager.
Open Report Template Designer.
Select File > Open and open the report template.
In the Designer view (Designer tab along the bottom of the Report Template Designer), find the table cell or Label that the script is to affect. Click this cell.
This will reveal a small > button above the cell. Click this button.
On the resulting Table Cell Tasks dialog, clear the Text field and ensure the Data Binding field is set to "None".
Click away from the Table Cell Tasks dialog to dismiss it.
The cell selected in step 4 should now have no text in it. Right-click this cell or label and select Properties.
On the resulting Property Grid view, expand the Scripts row. The Scripts row is in the Behavior category.
Click on the "Before Print" row.
Click the down arrow button that appears in that row.
Paste or compose the intended script within the curly brackets { } of the new function. Be sure not to delete or overwrite the function declaration line (private void...{ ) and closing curly bracket.private void xrTableCell20_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { // paste script here}
Preview the report by clicking the Preview tab.
If the results are acceptable, use File > Save to save the template or File > Save As to save it as a new template.
Close the Report Template Designer.
To modify an existing script, click the Scripts tab at the bottom of Report Template Designer and find the script.
On the resulting Property Grid view, expand the Scripts row.
Click on the "OnBeforePrint" row.
Click the [...] button that appears in that row. This will open a Script Editor dialog showing the current script for the OnBeforePrint event.
Paste, compose, or modify the intended script within the curly brackets { } of the function. Be sure not to delete or overwrite the function declaration line (private void...{ ) and closing curly bracket.private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { // paste script here}
Preview the report by clicking the private void xrTableCell20_BeforePrint tab.
To modify a script, repeat steps 4 through 7.
To remove a script, repeat steps 4 through 7 and click the Default Script button on the Script Editor dialog.
Concatenating fields on report templates
Add leading zeros to numbers on reports
Removing Terminal CP Text from Wire Lists
Replacing caret characters on reports
Scripting Overview - DevExpress