Paging in toolbar off-by-one
-
Tuesday, March 14, 2006 7:46 PM
I'm using the ReportViewer control in a WinForms project, using Local processing mode. On the report itself, it always correctly shows the current page and total number of pages in the report using Globals!PageNumber and Globals!TotalPages. However, in the toolbar page navigator, the total number of pages is always initially shown as one less than the actual number of total pages. For example, I've got a report that actually has 8 pages. When I view the report in ReportViewer, in my report header it indicates "Page 1 of 8". However, in the ReportViewer toolbar page navigator, it indicates "1 of 7".
Strangely, when I click "next page" in the toolbar, the total count is then correctly updated (using the above example, the toolbar then indicates "2 of 8"). The problem is the initial total page count in the toolbar is wrong. The problem only happens when using DisplayMode.PrintLayout -- it doesn't happen with DisplayMode.Normal. However, I don't want to use DisplayMode.Normal, as this gives a fully different page count than will actually be printed.
This happens with all my reports, and I've played around with margins, use of headers & footers, but the problem is consistently there. Any ideas?
Answers
-
Tuesday, March 28, 2006 8:19 PM
Yes, must be a bug...
I use this as a workaround, find in another thread.
private void reportViewer1_RenderingComplete(object sender, RenderingCompleteEventArgs e){
reportViewer1.SetDisplayMode(
DisplayMode.PrintLayout);reportViewer1.ZoomMode =
ZoomMode.PageWidth;}
All Replies
-
Wednesday, March 15, 2006 6:33 AMModeratorThis sounds like a race condition in the report viewer, though I have not seen it previously. Which report viewer events are you wired up to, if any? Can you post a sample application that demonstrates the problem?
-
Wednesday, March 15, 2006 10:59 PM
I'm not wired up to any events ... I posted a simple project which illustrates this problem to http://www.sofnalaska.com/pagingtest.zip. This test project doesn't require a database (it just manually fills up a DataTable). When you run the project and then click the "run report" button, you'll notice the page position on the report itself is 1 of 4 (these figures are from Globals!PageNumber and Globals!TotalPages). However, on the toolbar, the page navigator initially lists the page position as 1 of 3.
-
Tuesday, March 28, 2006 3:35 PM
Get the same problem here. Did you find a solution ?
Thanks
Rich
-
Tuesday, March 28, 2006 5:58 PM
Nope, no solution, & no response from MS since I posted the requested project. I was beginning to think I was crazy from the lack of response on this one! This problem happens for every single report I have (25+), and as best I can tell, it must be a bug in the toolbar code. It is particularly annoying when there are actually two pages in the report. Then the toolbar shows 1 of 1, and because it thinks there is only one page, it disables all the prior/next navigation buttons. Then the only way to view page two is to type 2 into the page field on the toolbar.
-
Tuesday, March 28, 2006 8:19 PM
Yes, must be a bug...
I use this as a workaround, find in another thread.
private void reportViewer1_RenderingComplete(object sender, RenderingCompleteEventArgs e){
reportViewer1.SetDisplayMode(
DisplayMode.PrintLayout);reportViewer1.ZoomMode =
ZoomMode.PageWidth;}
-
Tuesday, March 28, 2006 11:55 PM
Rich, you're a lifesaver! I've spent way too many hours trying to figure out a workaround for this problem. So, the bottom line on this bug is, apparently, if you use SetDisplayMode(DisplayMode.PrintLayout) before the report rendering is complete, the toobar paging will be off by one.
Thanks again, -Kent
-
Tuesday, May 30, 2006 12:54 PM
The workaround works, but not well. Try switching to normal mode. When rendering is complete, the event will fire and switch to Print preview mode!
This would be ok if there was a way to hide the print preview button altogether,but there doesn't seem to be (without hiding the whole toolbar, that is)? -
Tuesday, May 30, 2006 2:00 PM
This is my workaround. It's real ugly having to use reflection to read private variables, but I need to know whether reportviewer is in PrintLayout or not. Ugly, but it works:
void reportViewer_RenderingComplete(object sender, RenderingCompleteEventArgs e)
{
try
{
Type t = typeof(ReportViewer);
FieldInfo fi = t.GetField("m_viewMode", BindingFlags.NonPublic | BindingFlags.Instance);
DisplayMode dm = (DisplayMode)fi.GetValue(reportViewer);
if (dm == DisplayMode.PrintLayout)
{
reportViewer.SetDisplayMode(DisplayMode.PrintLayout);
reportViewer.ZoomMode = ZoomMode.PageWidth;
}
}
catch { }
} -
Thursday, June 01, 2006 6:29 AM
This is my improved workaround. It fixes some issues; When rendering completed it would jump to the first page. Also, there were some issues with switching to Normal mode.
void reportViewer_RenderingComplete(object sender, RenderingCompleteEventArgs e)
{
try
{
if (e.Exception == null)
{
Type t = typeof(ReportViewer);
FieldInfo fi = t.GetField("m_viewMode", BindingFlags.NonPublic | BindingFlags.Instance);
DisplayMode dm = (DisplayMode)fi.GetValue(reportViewer);
if (dm == DisplayMode.PrintLayout)
{
int pageNo = reportViewer.CurrentPage;
reportViewer.SetDisplayMode(DisplayMode.PrintLayout);
reportViewer.CurrentPage = pageNo;
}
}
}
catch { }
} -
Tuesday, June 06, 2006 9:46 PMModeratorWe have verified this bug. A hotfix is available for this issue by contacting Microsoft support. It is related to the printing issues I described in this thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=177732&SiteID=1&PageID=2
-
Wednesday, June 14, 2006 7:48 AMhow to get the hotfix?
-
Tuesday, June 27, 2006 1:29 AMModeratorThe hotfix is available by contacting Microsoft support: http://support.microsoft.com/contactussupport/?ws=support
-
Tuesday, June 27, 2006 10:07 AM
Dammit, whats up with hotfixes only being available by contacting support?
Put them up for download!When is a proper Service Pack going to be available? There are countless bugs to be fixed in ReportViewer..
-
Thursday, April 19, 2007 4:34 PM
Is this fix included in SP1? Replies to some other threads sound like it should be, but I've installed it and am still seeing the problem when I run the sample program referenced above. Do I still need the hotfix?
Thanks in advance,
Leanne
-
Monday, May 14, 2007 7:42 PM
I have SP1 installed (and have verified as such, per the instructions in the SP1 sticky thread), but am still having the same problem as the OP with the total number of pages in the toolbar being initially off by one. With SP1 installed, I can download/run the OP's test project and see "1 of 3" where it should display "1 of 4". Clicking the "next" arrow makes it correct itself.
Has anyone been able to successfully correct this using either SP1 or by getting the hotfix from MS? I have tried the work-arounds described here, but the results are inconsistent in my project, and I'd rather not go that route, if the bug has really been fixed.
Thanks again,
Leanne
-
Tuesday, December 04, 2007 6:02 PMI have not been able to fix this issue with ReportViewer + SP1 or using the KB916812 or KB917766 hotfixes.
This appears to be an on-going issue that is not getting resolved or just ignored. Has anyone found a fix yet? -
Tuesday, December 04, 2007 6:30 PM
I ended up contacting Microsoft support to try to get a fix, but neither SP1 nor any of the hotfixes worked for me either. Apparently there was an early pre-SP1 hotfix, but I was unable to install it myself, as it was not compatible with my current software version (a later one, using SP1). The fix did not make it into SP1, but the problem is fixed in Orcas. I opted not to escalate the case (as it's not a business critical issue at the moment) and just hold out for the upgrade.
If you need a fix and can't wait for the upgrade, you'll probably have to contact MS support and get them to make you one.
Good luck...

-
Wednesday, February 27, 2008 8:44 PM
Just to update in case anyone else is having trouble with this, I've upgraded to Visual Studio 2008 and the problem is indeed fixed.
-
Friday, March 14, 2008 6:57 PMI was able to fix this on a client machine by installing the full version of the Report Viewer Redistributable Package, found here.

