Many a times, while working with PageReport we have wondered why we are unable to access the page collection of page based reports and do something as simple as find total number of pages in the report created. The answer lies in the fact that these reports are not only different in terms of designing and functionality offered, their reporting engines are also individually distinct.
In this blog, we will discuss how to find the total pages in a PageReport document using our Winviewer programatically.
We will use the ToolStrip of our WinViewer and the value of it's 'Current Page' item to get the Total Page Count . 'CurrentPage' is 21st item in the Viewer Toolbar's ToolStripItem Collection, all we need to do is parse it's text and use it as required.
The GetTotalPageCount() method will look like this:
private int GetTotalPageCount()
//Get textbox in viewer toolbar and abstarct the total page count.
var pgtext = viewer1.Toolbar.ToolStrip.Items.Text;
int totalPageNumber = 0;
Int32.TryParse(pgtext.Split('/').Last(), out totalPageNumber);
How did we know that the Current Page item is at 21st position? WinViewer of ActiveReports is very flexible and highly customizable control. A list of all ToolStrip items with their position is available in the documentation to customize the viewer as per our needs.
A sample application showcasing the above implementation can be downloaded from the links below:
Download C# Sample
Download VB.NET Sample