Add a Title Page to a Report
- 3 minutes to read
This topic describes how to design a title page as a separate report and merge it to the base report.
Note
There are certain limitations when using report merging to add a title to a report.
Create a Title Page Report
In the PROJECT menu, select Add New Item… (or press CTRL+SHIFT+A) to invoke the Add New Item dialog. In this dialog, select the DevExpress v18.2 Report item.
Set the report name to XtraReport2 and click Add.
In the invoked XtraReport Wizard, select Blank and click Finish.
Drop an XRLabel onto the report’s Detail band.
Switch to the Field List and right-click the Parameters item. In the invoked context menu, select Add Parameter.
In the Add New Parameter dialog, set the Parameter.Name property to paramPaymentDate and the Parameter.Type property to DateTime. Disable the Show in the parameters panel option.
Double-click the XRLabel and set its Text property to “Products Report for [?paramPaymentDate]“.
To apply a format string to the parameter, invoke XRLabel’s smart-tag and define the Format String as {0:MMMM, yyyy}.
Add a Title Page to a Report
Report merging is available after report documents have been generated. Handle the base report’s XRControl.AfterPrint event, which is raised after the report document is generated, to access the report’s (XtraReport.ModifyDocument) method. Use the XtraReport.CreateDocument method to generate a document for the title page report.
private void XtraReport1_AfterPrint(object sender, EventArgs e) {
//Create a new title report instance
XtraReport2 titleReport = new XtraReport2();
// Set the paramPaymentDate parameter
titleReport.Parameters["paramPaymentDate"].Value = DateTime.Today;
// Generate the report document
titleReport.CreateDocument();
// Enable this property to maintain continuous page numbering
PrintingSystem.ContinuousPageNumbering = true;
// Insert the first page from the title report into the beginning of the base report
ModifyDocument(x => {
x.InsertPage(0, titleReport.Pages[0]);
});
}
Preview and Publish the Report
You can now preview the report. Refer to the following topics to learn how to do this in different platforms: