ActiveReports 6 Online Help
Custom Preview Sample

The Custom Preview sample consists of a parent CustomPreviewForm with menus, a child PreviewForm with an ActiveReports Viewer control, an ExportForm with a PropertyGrid, a Reports folder with six reports, and a Resources folder with six icons.

CustomPreviewForm

The CustomPreviewForm has its IsMdiContainer property set to True. This ensures that when a user opens a child PreviewForm, it is contained within the parent CustomPreviewForm.

This form has a menu bar, mnuMain, with three menus: File, Reports, and Window. The MergeType property of the File menu is set to MergeItems so that the menu items from any child PreviewForms are added to it. The form also has two dialogs: dlgOpenFile, and dlgPrint.

Right-click the form and select View Code to see how reports selected from the Reports menu are run and passed to the PreviewForm using the ShowReport code.

PreviewForm

The PreviewForm has the ActiveReports Viewer control with it Dock property set to Fill so that the viewer resizes with the form at run time. The form also has a File menu with its MergeType set to MergeItems so that when a report is open, the File menu on the CustomPreviewForm displays the Export, Save, and PrinterSetup menu items. The form also has one dialog: dlgPrint.

Right-click the form and select View Code to see how, in the PreviewForm Load event, two custom buttons are added to the toolbar. The ToolClick event of the viewer calls the SaveDocument and ExportDocument functions for the new buttons. The menu item click events call the same functions for the related menu items.

The SaveDocument function opens the dialog dlgSave, while the ExportDocument opens a new ExportForm.

ExportForm

The Export Report Document form opens from the ExportDocument function on the PreviewForm. The form features an Export Format combo box, cboExportFormat, that populates the PropertyGrid control below based on the selected item. The export types are added to cboExportFormat via the Items (collection) property.

Right-click the form and select View Code to see how, in the cboExportFormat SelectedIndexChanged event, the property grid control's SelectedObject is set to the selected export. This ensures that only the properties related to each export type show in the grid.

See the btnOK Click event for the code that exports the report to the selected file name and format, and the btnSaveFile Click event for the code that opens the Save dialog.

Resources Folder

This folder holds the icons used in adding tools to the toolbar.

Reports Folder

Most of the reports in the Reports folder are documented in more detail elsewhere. Here, they are used mainly to show the Viewer and Export features.

Catalog Report

The Catalog report uses the PageBreak control and the NewPage property to create a cover at the beginning and an order form at the end of the catalog. It uses grouping to list products by category.

ReportHeader

In the top of the ReportHeader section, the Picture, Line, and Label controls are used to create a static cover page for the catalog. The PageBreak control allows a second page of static labels to be set up in the same section, and setting the section's NewPage property to After ensures that the report breaks to a new page before rendering the next section. The ReportHeader section prints once per report.

PageHeader

This section is not in use, so the Height property is set to 0. This section cannot be deleted because its related PageFooter section is in use.

ghCategoryName

This GroupHeader section has its DataField property set to CategoryName. This, along with sorting the data by the same field, ensures that all of the details for one category are printed before the report moves on to the next category. Also, the section's GroupKeepTogether property is set to All. This causes ActiveReports to attempt to print the group header, related details, and the group footer together all on one page.

The controls in this section include two bound TextBox controls and a bound Picture control, along with a row of labels to serve as column headers for the Detail section to follow.

Detail

Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog, where you can see the Connection String and SQL Query that provide data for the bound fields.

The Detail section has four bound TextBox controls. Select one of them and you can see in the Properties window the field that it is bound to in the DataField property. The UnitPrice text box also uses the OutputFormat to display the data in currency format. This section prints once for each row of data.

gfCategoryName

This section is used only to render a horizontal Line control after each category grouping is completed.

PageFooter

This section is used to display the page number at the bottom of each page.

ReportFooter

This section has the NewPage property set to Before to ensure that it begins at the top of a new page.

Label, Shape, and Line controls are used to create the static order form layout in this page-long report section that prints once at the end of the report.

See Also

How To