472,102 Members | 1,083 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,102 software developers and data experts.

MDI parent to child communication problems

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!
Nov 20 '05 #1
2 3299
Have you tried using the Parent Property on the Child forms?

"Jim Shank" <go**************@spamgourmet.com> wrote in message
news:93**************************@posting.google.c om...
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!

Nov 20 '05 #2
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
"Mike Bulava" <mb*****@comcast.net> wrote in message news:<uL**************@TK2MSFTNGP10.phx.gbl>...
Have you tried using the Parent Property on the Child forms?

"Jim Shank" <go**************@spamgourmet.com> wrote in message
news:93**************************@posting.google.c om...
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!

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Paul | last post: by
16 posts views Thread by Suzanne Vogel | last post: by
3 posts views Thread by Maheshkumar.R | last post: by
6 posts views Thread by Edwinah63 | last post: by
10 posts views Thread by Goran Djuranovic | last post: by
2 posts views Thread by epaetz | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.