DESCRIPTION

The End User Designer which is a part of the professional edition of ActiveReports 8, allows you to host the report designer in your own Windows Forms applications and allow your end users to create and modify their own reports. You can find the article from our documentation – Basic End User Designer – with information about creating a basic End User Designer (referred to as EUD hereafter). This article is trying to showcase some additional functionalities – like adding a sub report without writing any code – that you add to your implementation of End User Designer.

THE PROBLEM

The good thing with ActiveReports is that it already provides samples demonstrating and talking about different functionalities available in the product and the EUD. A user can use all the report features in the EUD; however using a subreport in the EUD is a non-trivial task as there is no option to create multiple reports simultaneously. In addition to this if we want to use a subreport in the EUD, then a lot of script code is required to achieve the desired results. The complexity increases as the report layout for the subreport has to be saved on the disk to be used later. A typical code example can be found in the article - Script for Subreports - from the documentation. In this article, I would like to present an enhanced version of the End User Designer (using the shipped sample) which allows creating and using subreports without writing a single line of code. This will enable us to save the report layouts in memory, which will be added to a list present in the toolbar. The image below will make it clearer: SaveReport Finally when we are done with the creation of report layouts for the subreport and drag a subreport control to the main report, we will have an option to select report for the subreport either from the list of reports which we added or specify it from a physical location. The next image provides a better idea about this: LoadReport

IMPLEMENTATION

Though it sounds pretty straightforward but there are lots of things which need to be considered when approaching it. Let us find out what it takes to achieve this functionality:

  1. The first step involves adding a combo box and a button to the End User Designer tool strip which we will use to save the report layouts in memory.
  2. Next steps involve adding two forms to the project which will act as a save dialog and the report selection dialog (once the reports are saved).
  3. Till now it sounds like a pretty simple implementation, but now starts the tricky part. First of all we need to check whether a control which is dropped in the main report is a Subreport and which section it has been dropped onto. The LayoutChanging event allows this check to be performed.
  4. If the condition in the previous step is true then the “Select Subreport” dialog box is popped up so that a report can be supplied to the control.
  5. We select a report and set it as a subreport, but there are many things which happen between selection and showing of the subreport. When a subreport is selected, a SubReportDataObject is created with three properties (subreport name, section name, and subreport data) where subreport data is the string form of the rpx file. Let me first make it clear that the RPX (report layout) file is an XML and we are using stream to save and load the report. The main issue which arises when saving the reports is that the XML tags are automatically modified and therefore we need to find some way to get it back to same pattern which an RPX file should have. This is mandatory or else we would not be able to load the report in the subreport control.
  6. The reversion of the pattern to its original form has to be done via script and in the ReportStart event. We would not want to do this everytime we save and load a report, so the question is how to automate this process? To do this, we need to add a resource file to the project which contains two strings.:
    1. If ReportStart event is already present in the report script. This is required as it might be possible that a user has already written something to the script section of the main report.
    2. If ReportStart event is not present in the report script.
    3. Both these variables contain script code which is added to the main report automatically on the basis of the presence of the ReportStart event. The added script decodes the contents of the userdata and assigns the subreports accordingly.
  7. Now we should be able to display the subreport properly on preview; however there are still many conditions which have to be checked once a report is assigned to the subreport control. It is possible that a user moves the subreport to a different location/ section, renames the control, renames the section containing the subreport. All these changes have to be considered as well.

Once all the steps have been completed, we should be ready to use the design reports using subreports in the End User Designer. If it sounds too complex then you should take a look at the – Enhanced – End User Designer – sample application where I have demonstrated how to incorporate all the above mentioned steps. To make it clearer, I have divided the additional code (apart from the code which is already present in the shipped End User Designer sample) into different sections. I hope this would help users to design their reports quickly and effectively. P.S: The sample application currently uses ActiveReports 7 references, so that anyone using ActiveReports 7 can also use it.