Planning Your Application
Integrating reports is an easy way to add value to your application, and can be an important component of your application's offering. Before we get started on actually integrating Crystal Reports.NET with your Windows application, we need to do a little planning first to make sure the integration goes smoothly.First, we need to have a report (or suite of reports) to work with - in Chapter 2, we walked through the report planning and design process, so you should have a start on the skills you need to design reports.
NoteIf you flipped straight to this chapter or haven't gotten into designing your own reports yet, there are some sample reports located in C: \program files\Visual Studio.Net \Crystal Reports\Samples\ that you can use to practice concepts from chapter; alternately there are the sample reports included in the download file as well.
We need to plan for how those reports will be delivered to users and the Forms that will be required to host them. Crystal Reports.NET uses a feature-rich report viewer that can be inserted onto a Windows Form and used to view reports. The viewer itself has an extensive object model, allowing you to set the source of the report, the appearance of the viewer itself, and what happens when different events fire.
Most applications can utilize a single Windows Form hosting the Crystal Report Viewer and simply pass properties like the report source and viewer settings to this Form. This lends itself to a number of creative solutions for user personalization and settings. You could store viewer settings and preferences in a table or XML file for each user (or group or role) and apply these settings when viewing a report.In addition, you could also set specific record selection formulas for different groups of users, only allowing them access to the data applicable to them. You could also create a custom user interface allowing users to set and retain parameter settings for future use, or even in order to keep their printing or export preferences, such as frequently used e-mail addresses.Ultimately, the report integration should be driven by the user's requirements but how these features are delivered is up to you. As you go through the rest of the chapter, think about how the different customization features could be used in your development. If you are not at a point where you can integrate these features into your application, all of the properties, methods, and events are grouped together by function to make it easier to come back and look them up.
Exploring the Development Environment
Visual Studio .NET provides a rich integrated design environment for developing Windows and web applications and there are a number of components and shortcuts to help us integrate Crystal Reports into Windows Applications.To start with, in the toolbox under the Windows Forms section, you will find the CrystalReportViewer, which we will be working with a little later. When you draw this viewer on a Windows Form, you can set a number of properties and use the viewer to display a preview of your report.

In addition to the CrystalReportViewer, there is also a ReportDocument component available in the components section of the toolbox. We use this component to add strongly-typed and untyped reports to a Form, for use with the viewer mentioned earlier. (Don't be too worried about it at the moment, as we'll cover that a little later in the chapter.)And finally, the majority of our report integration will take place in the code view of the Form, as shown below.

All of the properties, methods, and events related to Crystal Reports object models and integration can be set and modified through this view, as well as through the Properties window.

Starting a New Windows Application with VB.NET
To get started with this chapter, we need to create a new Windows Application using Visual Basic.NET. If you want to follow along with the sample code that is available for this chapter, you will find a number of projects within that correspond to the sections in this chapter. If you want to get down and get your hands dirty creating your own project as we go along, then from within Visual Studio select File | New| Project and from Visual Basic Applications, select Windows Applications and specify a name (in the sample code, we have called this project viewer_basic and we have saved it to C:\CrystalReports\Chapter03).

Throughout the chapter, we will be using only one or two Forms to demonstrate different integration features - your own applications will probably have multiple Forms and launch reports from any number of them, but the same concepts can be applied.Before we actually look at any code, we need to go back to the integration features that you want to incorporate into your application and select the appropriate object model(s).