Skip to Content
Author's profile photo Bhushan Hyalij

Dealing with ‘CrystalReportViewer’ control – Part 1.

In Crystal reports .NET or Java application development, Crystal report viewer plays a vital role and is the only control which views a Crystal report.

This blog provides few guidelines on how to use, customize the viewer and how to deal with viewer related (report viewing) issues.

What is ‘CrystalReportViewer’ control and how to use it?

The CrystalReportViewer control is used in the .NET Framework to bind to and display reports. The default CrystalReportViewer control includes UI elements to assist in viewing, saving and navigating through a report.

The  CrystalReportViewer control for Windows applications, accessed through the ‘CrystalDecisions.Windows.Forms.CrystalReportViewer’ class, and the CrystalReportViewer control for Web site, accessed through the ‘CrystalDecisions.Web.CrystalReportViewer’ class.

Note that a CrystalReportViewer control is only necessary if you intend to display Crystal reports.

For more info. Check out the ‘How Do I Use Report Viewer Controls?’ section in CR.NET SDK developer guide.

Including a viewer control on a win or web form is as simple as dragging it from the toolbox and drop it onto the form. If the viewer is not available in the toolbox, go to ‘Choose items’ and check the respective viewer control, win or web. If the list does not contain any viewer controls, it means CR is not properly integrated with VS. CR should always be installed on top of / after VS for proper integration. Also, CR version compatibility with VS is very important.

Once the control is available you could assign a reportsource to the viewer. The source is the rpt file you would want to display. (Refer to ‘Setting the report source’ section in dev guide.)

CrystalReportViewer properties.

The CrystalReportViewer class provides a bunch of properties for customizing the viewer control and show hide the buttons.

Properties could be either set through code or from Visual studio IDE – viewer properties.

Viewer properties in VS IDE                                                             Viewer property APIs. (Click the image to enlarge)

CRViewer properties combined.jpg

See the brief description of viewer properties in CR.NET SDK API reference guide.

These properties are mainly used for

·         The CrystalReportViewer toolbar can be removed from the viewer.

·         The buttons on the CrystalReportViewer toolbar can be added or removed programmatically.

Customizing the CrystalReportViewer control

Apart from setting above properties, viewer control could be customized further.

Both Windows and Web CrystalReportViewer classes provide APIs to customize the viewer.

Viewer customization includes –

·         Customizing Report Processing Indicator – Change image, text.

·         Supporting multiple languages with the CrystalReportViewer control – Changing Locale

·         Handling Error Events – e.g. OnError, OnNavigate events

·         Customizing the CrystalReportViewer Control with CSS – Extending the viewer style.

·         Customizing the CrystalReportViewer Control with Themes

·         Customizing the CrystalReportViewer toolbar – Show hide viewer buttons, toolbar.

All above are explained in detail with code in CR.NET SDK Developer Guide.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.