Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Wrox Professional Crystal Reports for Visual Studio NET Second Edition phần 5 pdf
Nội dung xem thử
Mô tả chi tiết
04 557300 Ch04.qxd 3/24/04 9:36 AM Page 130
Chapter 4
Speaking of different types of users, the next section deals with how to customize the appearance and
layout of the viewer itself. So in addition to showing them only the records they want to see, you could
also give them their own custom viewer with which to view the resulting report.
Customizing the Appearance and
Behavior of the Report Viewer
The CrystalReportViewer class contains all of the properties, methods, and events that relate to the
viewer itself, its appearance, the methods that are used to make the viewer perform certain actions (like
refresh or print a report), and events that can be used to determine when a particular event (such as
drill-down or refresh) has occurred. To start learning how to work with the viewer, we are going to start
with the basic properties and move on from there.
When previewing your report, you may notice that there is a standard set of icons and layout that
appears on your viewer by default, but you can control most of the aspects of the viewer by setting a few
simple properties for the Crystal Report Viewer in the Properties window, as shown in Figure 4-16.
Figure 4-16
The area at the top of the viewer is the toolbar, which can be shown or hidden as an entire object, or you
can choose to only show certain icons. On the left-hand side is a Group Tree, generated by the grouping
that you have inserted into your report. The properties that control these general properties are Boolean
and are listed below:
130
04 557300 Ch04.qxd 3/24/04 9:36 AM Page 131
Report Integration for Windows-Based Applications
Property Description
DisplayBackgroundEdge For showing the off-set edge around your report when
previewing
DisplayGroupTree For showing the group tree on the left side of the viewer
DisplayToolbar For showing the entire toolbar at the top of the viewer
All of these properties default to True and you cannot change the position of any of these elements; they
are fixed in place on the viewer. You can, however, hide the default toolbar and create your own buttons
for printing, page navigation, and other functions, and we’ll look at that a little later in the chapter.
For the icons within the toolbar, you can also set simple Boolean properties to show or hide a particular
icon, as shown here:
❑ ShowCloseButton
❑ ShowExportButton
❑ ShowGotoPageButton
❑ ShowGroupTreeButton
❑ ShowPageNavigateButtons
❑ ShowRefreshButton
❑ ShowTextSearchButton
❑ ShowZoomButton
❑ ShowPrintButton
So a typical use of these properties is where you want to give users a view-only preview, with no printing or
exporting options and no option to refresh the report. Going back to our original report (ch4_worldsales),
we could easily set a few properties before you set your ReportSource property to make this happen.
Double-click anywhere on your form to open the code view and in the form’s Load method, enter the
following:
...
End With
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTableLogonInfo.TableName = “customers”
myTableLogonInfos.Add(myTableLogonInfo)
CrystalReportViewer1.LogOnInfo = myTableLogonInfos
CrystalReportViewer1.ReportSource = myReport
CrystalReportViewer1.DisplayGroupTree = False
CrystalReportViewer1.ShowExportButton = False
CrystalReportViewer1.ShowRefreshButton = False
CrystalReportViewer1.ShowPrintButton = False
CrystalReportViewer1.ReportSource = New ch4_worldsales_northwind()
End Sub
131
04 557300 Ch04.qxd 3/24/04 9:36 AM Page 132
Chapter 4
When the report is previewed, it will appear as shown in Figure 4-17.
Figure 4-17
Keep in mind that you can set these properties any time prior to the report preview. You could store individual user or security settings in your application data and then set the appropriate properties prior to
viewing the report. This is just one example of where we can customize how a report is presented to the
user; the next section on the methods available within the viewer takes that discussion one step further.
Viewer Methods
When working with the Crystal Report Viewer, we have a number of methods available to us, which
will allow us to integrate specific viewer functions into our application. As we move through this
section, keep in mind that these methods can be used to create your own look and feel for the report
preview window, as shown in Figure 4-18.
During the course of this section, we will actually be looking at the code behind the custom viewer
shown here, so it is probably not a bad idea to start a new project within this chapter’s solution file. To
create a new project from within Visual Studio, select File → New → Project and from Visual Basic
Projects, select Windows Application and specify a name, as shown in Figure 4-19, (in the sample code,
we have called this project viewer_methods) and location for your project files. Remember to set this
project as your startup project.
132