Introducing the Crystal Reports Visual Studio 2010 WPF viewer
page 4 of 6
by Eric Landes
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 46977/ 69

Creating a New Reporting Application with the WPF Viewer

The new WPF viewer control to use in your windows applications is a slick new control.  It looks better and has some newer features, as revealed in the API section above.  As of Beta 2, binding a report to the viewer is done most easily programmatically. 

If you want to allow the end user some control of what report to view, enable the property ShowOpenFileButton to allow the user to select a report.  Eventually there will be a property to set this, but you can set the report to an embedded resource using code.  For instance, in example 1, the code shows how to bind an embedded resource to the report viewer. 

CrystalReport1 is a report created in a project.  To bind this report to the new WPF viewer, use the property ViewerCore.ReportSource and set it to the instance of the embedded report.  Code Sample 1 shows the code.

Listing 1

reportViewer.Owner = this;
CrystalReport1 newCR = new CrystalReport1();
reportViewer.ViewerCore.ReportSource = newCR;

Figure 1: Sample of viewer


The new control does have better graphics.  Besides better graphics the viewer also has built in performance benefits.  When filtering, if the data is not changed, the data does not get refreshed. 


For instance, if you use a parameter to hide or show an object on your report, the data would not be affected.  In the report shown in Figure 1, there is a print date that shows at the top of the report.  An object like this would be perfect to demonstrate the new refreshing strategy.


First, edit the report.  Add a parameter, named ShowPrintDate.  Make that parameter Boolean and set the default value to True.  Select the object containg print date, and open the format properties dialog box.  On the common tab, select the formula button beside the suppress checkbox.  In that formula box, enter the formula shown in code sample 2.


Listing 2

IIF ({?ShowPrintDate},False ,true )

That formula will allow you to toggle visibility of the print object on the report.  When you select and change that parameter, the report will not go back to the data store to refresh the data.  If you utilize these types of dynamic parameters in your reports, you should see some performance gains from this.

View Entire Article

User Comments

No comments posted yet.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2021  |  Page Processed at 2021-04-13 1:10:05 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search