mdi forms do not dispose [original post to Controls, by mistake]



* Apologies .. this is a duplicate of a msg posted in the Controls forum,
where I posted it first by mistake -- Jeremy

My mdi child has a shared execute method which creates and shows it. I'm
attempting to limit the number of instances of this specific child to 1.
When I close the form, it visibly goes away, but it remains in memory.
ComboBox events fire for every supposedly "closed" instance of
frmMyMDIchild. Obviously there is either a nasty bug in VB, or I completely
misunderstand something very basic. Help me out here!

- Jeremy

Public Class frmMyMDIchild
Inherits System.Windows.Forms.Form
Shared frm As frmMyMDIchild = Nothing
Private ImDead As Boolean = False 'for debugging

Public Shared sub Execute(mdiParent as Form)
If frm Is Nothing Then
frm = New frmMyMDIchild
With frm
.midParent = mdiParent
'Do some inits ...
End With
End If
End Function

Private Sub frmMyMDIchild_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
Me.ImDead = True
frm = Nothing
End Sub

Private Sub cbMyDropDown_SelectedValueChanged(ByVal sender as Object, ByVal
e As System.EventArgs) Handles cbMyDropDown.SelectedValueChanged
'This fires even for instances of frm where ImDead is True. ie: the
"Closed" frms are not closed at all.
msgbox(iif(ImDead,"Dead","Not Dead"))
End Sub

'** end **




Here's a curious additional fact. In my combobox, I'm using a datatable
from a Class as a datasource. If I simply populate the combobox in the ide
with a few items, the mdi forms actually seem to dispose when I say
"dispose". Here's the original code that sets up the combobox:

private sub setupComboBox

dim tbl as DataTable

'myTables is an instance of a class that persists after the form is
tbl = myTables.dsTables.Tables("KindOfGrain")
cbKindOfGrain.ValueMember() = tbl.Columns("CodeName").ColumnName
cbKindOfGrain.DisplayMember() = tbl.Columns("Kind").ColumnName
cbKindOfGrain.DataSource = tbl

end sub

I'm truly going nuts over this!


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question