Using the Windows Forms Report Viewer

Now that you have a report ready to run and you're familiar with the reports designer, you can create a form to actually view your report.

The first step is to add a new form to your solution by right-clicking the project name in the Solution Explorer and selecting Add, Add Windows Form from the contextual menu. You can leave the default Form1.vb or Form1.cs name.

Next, in the Toolbox, scroll down in the Windows Forms tab until you see the CrystalReportViewer control. Drag it onto your form, and set the Dock property to Fill so that it resizes with the form. Your form should look something like Figure 18.18.

Figure 18.18. Form1 after adding the CrystalReportViewer control.


The viewer on its own does nothing. You can either set a binding property to specify the report to load or you can programmatically load a report into the viewer. To view the Report1.rpt you created, press the F4 key to view the properties for the viewer control and select the ReportSource property. If you click the Browse option in the ReportSource property, the Open An Existing Crystal Report dialog pops up. Navigate to the correct directory of this solution and select Report1.rpt, as Figure 18.19 demonstrates.

Figure 18.19. Selecting the ReportSource for the CrystalReportViewer control.


After that property is set, you can press the F5 key to run the application. Like magic, the report that you created is displayed in a nice full-featured report viewer. Figure 18.20 is what you should see now.

Figure 18.20. Viewing the Report1.rpt in the report viewer.


The toolbar on the viewer enables you to page through, drill into (if it's a group report), print, and export a report. The exporting features of Crystal are especially useful. You have the option of exporting any report to an Excel spreadsheet, Word document, rich text document, or Adobe PDF document.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.131.255