How To…Automatically Navigate Within the Previewer

Question

“How do I automatically navigate/scroll once the preview is loaded?”

Solution

With the addition of the scrollable previewer for RB 14, it is increasingly necessary to automatically navigate or scroll to a pre-defined position inside a report.

This can easily be done by using the TppViewer.OnPrintStateChange event and the TppViewer.Busy property.

1. Access the TppViewer object directly or via the TppReport.PreviewForm.Viewer property to assign the necessary event(s). Note: To ensure the PreviewForm.Viewer has been instantiated, access it inside the Report.OnPreviewFromCreate event.

2. Before navigating the report, check that the TppViewer.Busy property is False.

3. Perform the report navigation using the built-in TppViewer routines or by directly accessing the vertical scrollbar and/or horizontal scrollbar.

Viewer Pagination Routines:

– TppViewer.First();
– TppViewer.Last();
– TppViewer.Next();
– TppViewer.Prior();
– TppViewer.GotoPage();

Scrollbar access:

– TppViewer.ScrollablePaintBox.VerticalScrollbar
– TppViewer.ScrollablePaintBox.HorizontalScrollbar

Additional Information:

In some cases, it may be necessary to save the current page number or scroll position for later use.

– Current Page Number
Use an event such as the Report.OnStartPage to save the Report.AbsolutePageNo for later use.

– Current Scroll Position
Use the TppViewer.OnScroll event to save the x or y positions for later use.

Download: PreviewAutoScroll.zip

Sample Delphi code: