Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I am developing an embedded report viewer which is used to view Server based SSRS reports (using the MS ReportViewer control). This control is embedded into my WPF window within a Winforms Host control (this works fine and is not causing the issue). The look of the standard toolbar of the ReportViewer did not fit with the app I am developing so I made my own. This works quite well, except...

The problem:
When I change the display mode to DisplayMode.PrintLayout the number of pages of the report always becomes 1 (regardless of how many pages are in the report when it is printed). This results in my page navigation disabling itself. I am able to focus the report itself and navigate using PageUp/PageDown or mouse scroll, however I have no way to use the navigation controls in my toolbar (as they think the report only has 1 page, and disable themselves).

To determine the number of pages in the report, I am calling:
myReportViewer.ServerReport.GetTotalPages(); within the event handler for the myReportViewer.RenderingComplete event.

The only lead I have is that the GetTotalPages() method which I use to get the total number of pages is described as returning the total number of "Logical" pages. Maybe this is different to physical pages?

My Question:
Is there a way to get the number of pages while in DisplayMode.PrintLayout mode?

Any assistance you can provide would be greatly appreciated :-)

Regards,
Mark
Posted

First of all, just check if you have adjusted the Interactive Height/Width of the report or not. That is important here.

If the problem persists, I got this thread which looks connected:
http://social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/0d14d697-d6d2-4399-9ad5-12861e35887c[^]
 
Share this answer
 
Thanks Sandeep, I had read that forum post earlier (was a little more helpful the second time I read it) :)

I'm pretty sure it's not related to interactive height settings, I've dealt with those issues before.

There is only one option that I've been considering, which is to extract the number of pages using reflection from a private member within the report viewer itself (ReportViewer.CurrentReport.FileManager.Count). I am, however, extremely reluctant to do this. Although it seems more appealing to me than rendering the report a second time (as suggested in the linked blog: http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/f9fc7120-4560-4f43-8ab1-c745ba11cbdf).
 
Share this answer
 
Hi Mark,

I don't like the idea of rendering for the second time to just get the page count.

Instead, I went down to the reflection path.

As Mark mentioned, ReportViewer.CurrentReport.FileManager.Count will have correct physical page count for print preview mode within the event handler for the ReportViewer.RenderingComplete event.

However, CurrentReport is a type of Microsoft.Reporting.WinForms.ReportInfo, which is a private class as well. Same as the FileManager, which is a private class type of Microsoft.Reporting.WinForms.FileManager. So we cant create a reference to those types. As a result, the reflection I did is a bit mess. Sort of a three layers reflection, reflection on top of reflection on top of reflection. ;) ;)

if (displayMode == DisplayMode.PrintLayout)
{
    PropertyInfo currentReport = typeof(ReportViewer).GetProperty("CurrentReport", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

    PropertyInfo fileManager = currentReport.GetValue(this.ReportViewer, null).GetType().GetProperty("FileManager", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

    PropertyInfo count = fileManager.GetValue(currentReport.GetValue(this.ReportViewer, null), null).GetType().GetProperty("Count", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

    this.TotalPages = (int)count.GetValue(fileManager.GetValue(currentReport.GetValue(this.Viewer, null), null), null);
}
else
{
    this.TotalPages = this.ReportViewer.ServerReport.GetTotalPages();
}


I know it is not elegant, but it works for us. :laugh: :laugh:

Nan
 
Share this answer
 
v4
Comments
Member 10415024 2-Feb-17 6:58am    
this.TotalPages = (int)count.GetValue(fileManager.GetValue(currentReport.GetValue(this.Viewer, null), null), null);

What object is Viewer? (this.Viewer)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900