Saturday, May 16, 2009

DevExpress XtraReports Tip – Managing page headings with subreports

Imagine that you need to produce a report that consists of a detail section and then a summary section that needs to start on the same page as the end of the detail section.

You could create both the detail report as separate reports and join them together with spanned page numbering.  This technique was presented in my webinar.  In this case, it is not the appropriate solution as it would always start the summary report at the top of a new page – not satisfying the same-page requirement.

Because of the same-page requirement, the summary report needs to be a Subreport element in the Report Footer of the detail report.

You will soon discover that this creates an issue with the page headings as soon as the Subreport prints on a new page.

When the Subreport prints on the last page, it will print both the Subreport report header and page header if present.  In order to get the combined detail/subreport page to look correct, you will want to leave the Subreport report header band blank and place all the heading elements in the page heading band.  The SubReport’s designer looks like this:

5-16-2009 9-24-57 PM

The page where the detail report ends and the Subreport begins looks like this:

5-16-2009 8-51-47 PM

The problem occurs when the subreport flows over to the next page.  The detail report has its column headings in its page header band and now the subreport will show its page header band too.  Without any further intervention, you will get a next page that looks like this:

5-16-2009 9-00-16 PM 

The black column headings row containing First Name  and its black line are not relevant for this page. They belong to the prior detail report which is no longer shown.  You cannot just suppress the detail report’s page header band since it contains the orange line area (typically report titles) that must be shown on all pages.

Below is the detail report’s designer page:

5-16-2009 9-16-08 PM

The solution is to change these unwanted elements’ visibility to false in the BeforePrint event of the XRSubreport1 element in the detail report.  I named each of the elements with a “ch” prefix to make them easier to find with IntelliSense.  The code looks like this:

5-16-2009 9-01-57 PM

With this single change, the Subreport overflow pages will look as desired, like this:

5-16-2009 9-05-01 PM

And there you have it.  I created this sample web application in Visual Studio 2008 and Developer Express XtraReports version 9.1 to illustrate the issue and its solution, using the Microsoft AdventureWorks sample database.  If you would like to download the full application to see it for yourself, you can download it here.

Hope that helps.

Joe Kunk
Microsoft MVP VB
Okemos, MI USA

No comments: