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