I'm using Visual Studio 2005 with VB.NET.
I have a number of Crystal Reports, each with their own associated dialog resource containing a CrystalReportViewer. The class definitions look like this:
Imports System.Windows.Forms
Imports CrystalDecisions.Crystal开发者_如何转开发Reports.Engine
Imports CrystalDecisions.Shared
Public Class dlgForMyReport
Private theReport As New myCrystalReport
Public theItems As New List(Of MyItem)
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub dlgForMyReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
theReport.SetDataSource(theItems)
'Do a bunch of stuff here to set data items in theReport
Me.myCrystalReportViewer.ReportSource = theReport
End Sub
End Class
I basically instantiate the dialog, set theItems to the list I want, and call ShowDialog.
I now have a need to combine several of these reports into one report (possibly like this) but the code that loads up the fields in the report is in the dialog.
How would I go about decoupling the report initialization from the dialog?
Thanks!
You could quite easily have a generic report viewing dialog that took an instance of the base class for the reports (I.e. CrystalReport
) and have it display that - you don't need to strongly type the report all the way through.
精彩评论