Skip to main content Skip to footer

Avoid Orphaned ReportFooter with GroupFooter's NewPage property as "After"

Grouping is one of the most commonly used feature when it comes to designing a report. Its implementation can vary from one report to another based on the requirements of the user. A very common scenario is starting each group from a new page. This helps in encapsulating the groups in one page or a range of pages, thus making it easier for a user to identify each group individually. The good thing here is that the GroupFooter section in ActiveReports provides a NewPage property which if set to "After", automatically starts the report from the next page, once the current group is completely rendered. **PROBLEM** If you want to add a ReportFooter section to a report designed with the specifications mentioned above, then in every case the ReportFooter section will always be orphaned on the last page. ReportFooter section can be very important for a report as there might be something which a user might want to display at the very end. Let us see how an orphaned ReportFooter looks like:

**REASON** In the above case the NewPage property for the GroupFooter section is set "After", and once the last group is completely rendered, ActiveReports engine checks if there is any other data left to be printed on the report. Since it finds a ReportFooter section waiting to be printed (as it contains some control), it inserts a new page and therefore the ReportFooter is moved to the newly added page, leaving it orphaned. **SOLUTION** The only way to solve this problem is to avoid using the ReportFooter section. This leads to another question that how will we be able to show the text we want to include in the ReportFooter section? Well the answer is pretty straightforward and we will be using the GroupFooter section to act like a ReportFooter. Let us find out how. Consider an example where you are looking to show a text "Report Ends Here" once the report ends. Considering our case where we cannot place the label in the ReportFooter section, we will have to place it in the GroupFooter section. The problem now is that the label will appear on every GroupFooter section. So we will keep the visible property of this label to false initially, setting it from the properties window. Since the label is now invisible, it will not appear on all the GroupFooter sections of the report. Now the only catch here is that we have to make the label visible once the last GroupFooter renders and to do this we need to know the number of main groups which are present in the report. This can be done by writing a query which does this work and also provides us a connection with the datasource. The images below from the connection dialog box and the designer will make it clearer:

Once we have written the query, we will get an additional field in the ReportExplorer which can be dragged and dropped onto the GroupFooter section. The purpose of doing this is that on every GroupFooter Format event we will check whether the current group number is equal to the total number of groups and once the condition satisfies, we will make the label visible. So the code looks something like:

int currentgroupno = 1;  
private void groupFooter1_Format(object sender, EventArgs e)  
{  
 textBox1.Text = "End Of Group " + currentgroupno.ToString();  

 //txtNoOfCountries1 is the field which contains the value for the total number of groups  
 if (currentgroupno == int.Parse(txtNoOfCountries1.Text))  
 {  
   label2.Visible = true;  
 }  
 currentgroupno++;  
}

A working example demonstrating this functionality can be downloaded from the following links. Download Sample C# Download Sample VB.NET

MESCIUS inc.

comments powered by Disqus