Re: showdialog and 'Cannot access a disposed object'
chris Burgess <[email protected]> Fri, 4 Jan 2008 11:49:49 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <[email protected]> |
I think what I really want is to have the report object hold the type of report form instead of a reference to the actual form object. I want the button to create a new form each time of the type listed in the list box/report object, and not reference existing objects. On Jan 4, 2008 10:53 AM, Peter Ritchie <[email protected]> wrote: > 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). >