MDI parent to child communication problems

J

Jim Shank

I am really trying to find the best OOP way of doing this. I have a
parent MDI form with multiple children and I am trying to communicate
variables between them. I have been able to successfully get the
parent form to read the child variable by using a Public Property in
one of my child forms like such:

Public ReadOnly Property ID() As String
Get
Return strID
End Get
End Property

When this value is updated I am having the child use the RaiseEvent to
get the parent form to then read this Property from the Child window:

strID = lstExistingID.SelectedItems(0).Text
RaiseEvent IDSelected()


Private Sub ChildFRM_IDSelected() Handles frmChild.IDSelected
strID = frmChild.ID
End Sub


The problem I am running into is now retrieving this variable from my
parent to a different child. It seems that I have to declare or
somehow define the form for the MDI Parent in order to access its
properties/functions. I can successfully create a reference in the
other child form using:

Dim frmMainMDIParent As fclsMainMDIParent

but as soon as I uncomment my Property get statement:

lstTransactionLog.Items.Add("Ready to process ID " &
frmMainMDIParent.ID)

I start getting an exception: An unhandled exception of type
'System.OutOfMemoryException' occurred in system.windows.forms.dll

Additional information: Error creating window handle.


From Main MDI Parent Form:
If e.Button Is tbbTransactionControl Then
frmTransactionControl.MdiParent = Me
If Not frmTransactionControl.Visible Then
stops here----> frmTransactionControl.Show()
End If
End If

I hope this provides enough information for someone to give me a
solution. I am also interested in any suggested reference sites/books
to show me the best way to handle inter-MDI communication. TIA!
 
J

Jim Shank

I assume you mean by using the directcast method such as:

strLocalID = DirectCast(Me.MdiParent, fclsParentForm).ID

to access the parent properties. This does in fact work but is it the
best OOP way to do it? I am toying today with using a separate module
to declare all of my classes and functions to instantiate the classes
so I can reference them outside the forms without redeclaring the
forms. When I redeclare the parent form in the child form is when I
get into the most trouble because it ends up in an endless loop (child
declares the parent which redeclares the child and so on until you get
an OutOfMemory exception). Thanks for your feedback and let me know
what else you think.


Jim
 

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

Top