logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • ru
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to make the same report pages with different headers
  • How to use SQL queries when creating an internal report data source in FastReport.Net report designer

    September 2, 2019

    When creating a SQL database connection, you can specify a query to select filtered or

    read more
  • How to connect the IBM DB2 database in reports designer FastReport.Net

    November 15, 2019

    To connect the report to a DB2 database, you need to connect the plugin to

    read more
  • How to hide columns in a list if there is no data

    April 7, 2020

    When making the report, we want it to be "friendly" to the consumers as much

    read more
  • How to create a sales receipt from a WinForms application

    May 30, 2020

    Most likely every .Net developer started from Windows Forms applications. Countless number of such applications

    read more
  • PreviewControl.OnPrint and PreviewControl.OnExport Events

    October 1, 2020

    In FastReport 2019.4 added the ability to subscribe to PreviewControl.OnPrint and PreviewControl.OnExport events, which are

    read more

How to make the same report pages with different headers

January 8, 2020

Sometimes your work needs one and the same report, but with a few changes. For example, different headers for different departments. So, for example, a user of the ActiveReports report generator wants to create such a report:

For example, the user select copies for the customer and for administration department.

The application creates the same report but each one has a label in the header that shows something like "Copy for the customer", "Copy for the administration department".

After, the application has to show the two pages in a form viewer.

Let's implement such a report in FastReport.Net. You can generate the same report and pass it different parameters for the header. But if you want to receive similar reports with different headlines in one report, you can do otherwise. We can duplicate the pages of the original report, and then modify the headers in these pages. The easiest way is to show on the report with one page.

The report will have a parameter that lists the number of titles that you want to display in this report through a comma. In the report script, we duplicate the page based on the number of values in the setting, then replace the text in the headlines of the new pages to the desired.

In this way, we can form pages with different titles depending on the numbers that are transferred. However, there is one difficulty. You'll have to manually calculate the number of the text object in which you want to replace the text. For example, there are 9 text objects in my report. The first is the headline. So the tenth will also be the headline, but on the new page. If you add another 9 to 10, we get the title number on the third page and so on.

It will become more clear when you the script code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
private void _StartReport(object sender, EventArgs e)
 {
 //Parse parameter
 string parameter = (string)Report.GetParameterValue("Parameter");
 string[] arr = parameter.Split(',');
 
 //Number of text obj that is header
 int step = 10;
 
 foreach (string item in arr)
 {
 ReportPage newPage = new ReportPage();
 newPage.AssignAll(Page1);
 Report.Pages.Add(newPage);
 newPage.CreateUniqueName();
 foreach (object obj in newPage.AllObjects)
 {
 if (obj is Base)
 { 
 (obj as Base).CreateUniqueName();
 }
 }
 TextObject txt = Report.FindObject("Text"+ step.ToString()) as TextObject;
 switch (item)
 {
 case "1":
 txt.Text = "Header 1"; 
 break;
 case "2":
 txt.Text = "Header 2"; 
 break;
 case "3":
 txt.Text = "Header 3"; 
 break;
 }
 step = step + 9;
 }
 Report.Pages.Remove(Page1);
 }

 Let's take a closer look at this script. We used the StartReport event at the Report object. In the event handler, we will manipulate the report pages. The report already has one page developed - in fact it is a ready-made "combat" report, on the basis of which we want to make several, but with different headlines.

First of all, we parse a report parameter. As mentioned earlier, the parameter is passed in sequence identifier patterns that we want to display. Identificators are separated by commas. Next, iterate loop parameter IDs obtained from the report. For each of them creates a page based on an existing text object is calculated with a header. Depending on the text object header template identifier is set. Once we have established a "pack" the necessary pages, remove the first page of the sample.

As a result, we get multiple reports within a single. A controlled number of these reports pages may be passing in the report parameter value - the desired combination of identifiers or headers.

 

about product download buy
avatar
Dmitriy Fedyashov
Head of QA
.NET FastReport

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Our team
  • Contact us

© 1998-2021 by Fast Reports Inc.

  • Privacy Policy