views:

72

answers:

1

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.CrystalReports.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!

+1  A: 

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.

Rowland Shaw
Thanks Rowland. If I understand correctly, then, I just load up the report data elsewhere, set and bind the CrystalReport object, and display the dialog?
John at CashCommons
@John exactly that. In effect, you'd change your code so that `theReport` becomes exposed as a property of type CrystalReport, you could then set it as a new `myCrystalReport` and show the dialog or any other CrystalReport object
Rowland Shaw
Worked like a charm. Thanks!
John at CashCommons