Re: showdialog and 'Cannot access a disposed object'
Peter Ritchie <[email protected]> Fri, 4 Jan 2008 10:53:12 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
On Fri, 4 Jan 2008 09:56:41 -0600, Mike Andrews <[email protected]> wrote: >The issue is that you're creating a new Report via this line: > >Dim rpt As New BaseReport > >and then destroying it and in place of it setting an existing one: > >rpt = DirectCast(Me.Reports.SelectedValue, BaseReport) > >since the list box contains the references to the report object, and you've >previously disposed it it will fail to run. >You need to refrain from calling the dispose() method until you're done with >the form in which the listbox resides. >You can then dispose all of the reports. Bingo, the Reports object should be responsible for disposing what it aggregates (or the owner of the Reports object if that class doesn't have that concept).