HowTo Identify Section OverFlow in ActiveReports
Recently one of our customer had a requirement in ActiveReports where he wanted to check when the detail section overflows to a new page and when not. The first thing which will come to our mind as an approach to solve this issue is that we may calculate the height of all the sections on the page and then accordingly find out a solution. However, practically this is not a simple thing to do and will require a lot of things to keep in mind while making this calculation. A simple and much easier answer to this problem is to make use of the section and report events to find out when a section overflows to a new page. In this blog, we will discuss the approach to do this. For implementation purpose, we will consider the example of the detail section.
Problem Statement
The report has long text in the detail section which sometimes may spill over to the next page. We wish to let the user know when the text has overflown to the next page. This may be done by showing a text of some sort (for example continued..) at the top of the overflown text to show that this is a continued text from the previous page. Let us see a picture how we expect it to look like:
The Solution
The solution is quite simple. Whenever a section overflows to a new page, its BeforePrint event fires on the first page and the AfterPrint event fires on the new page. We can declare a global Boolean variable (say isSectionPrinted) and set its value to false in the former event and true in the latter one. Finally in the PageStart event we can check the value of the Boolean variable and determine if the section is being continued to a new page. Here is the simple code which is all you need:
bool isDetailPrinted;
private void SectionReport1_ReportStart(object sender, EventArgs e)
{
isDetailPrinted = true;
label3.Visible = false;
}
private void detail_BeforePrint(object sender, EventArgs e)
{
isDetailPrinted = false;
}
private void detail_AfterPrint(object sender, EventArgs e)
{
isDetailPrinted = true;
}
private void SectionReport1_PageStart(object sender, EventArgs e)
{
if (isDetailPrinted == false)
{
label3.Visible = true;
}
else
{
label3.Visible = false;
}
}
Conclusion
This blog uses one scenario as an example. However there can be numerous other requirements which can be achieved using this approach. A sample application in both C# and VB.NET can be downloaded using the links provided below. Download_C#Sample Download_VB.NETSample