views:

31

answers:

1

Hi all

I have a number of report viewers set up, each of which can open a number of crystal reports. This all works fine.

I am wanting to streamline how i dispose of the reports in the DisposeOfReports() event.

At the minute i do the following:

 If (_rpt1 IsNot Nothing) Then
     _rpt1.Close()
     _rpt1.Dispose()
 End If

 If (_rpt2 IsNot Nothing) Then
     _rpt2.Close()
     _rpt2.Dispose()
 End If

Can this be done using an array?

I was thinking each time a report is generated I could add the report to the array.

Then in the DisposeOfReports() Event do something like:

If (reportsArray IsNot Nothing) Then

  For Each report As CrystalDecisions.CrystalReports.Engine.ReportClass In reportsArray

     If (report IsNot Nothing) Then
        report.Close()
        report.Dispose()
     End If

  Next

  reportsArray = Nothing

 End If

For this method I was going to declare reportsArray like this:

Private reportsArray As New List(Of CrystalDecisions.CrystalReports.Engine.ReportDocument)

Please can people feed back to me on this and let me know if this is a valid method of doing this or if there are better ways of doing it?

Cheers.

+1  A: 

I see nothing wrong with your approach.

thehowler