473,395 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Opening child from child within parent

Hi Guys,

I have a problem opening a child window within a parent window when passing
a variable between two child windows.

I have the parent window setup with two menuitems. The first calls Form2 and
the second calls Form3

The code follows:-

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click
Dim NewMDIChild As New Form2
NewMDIChild.MdiParent = Me
NewMDIChild.Show()
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
Dim NewMDIChild As New Form3
NewMDIChild.MdiParent = Me
NewMDIChild.Show()
End Sub
On Form2 I have a button which calls Form3 with some text I wish to display
in Form3
Form2 Code follows:-

Private ShowForm3 As New Form3(Me)

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Label1.Text = "Text to Send"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim NewMDIChild As New Form3
Dim ShowForm3 = New Form3(Me)
ShowForm3.MdiParent = Me.MdiParent
ShowForm3.Show()
End Sub

The code on Form3 is as follows:-

Private CallingForm As Form2

Public Sub New(ByVal newCallingForm As Form2)
MyBase.New()
InitializeComponent()
CallingForm = newCallingForm
End Sub

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = CallingForm.Label1.Text
End Sub
If I open Form2, click on the button to open Form3 and display the text, all
is OK.
If I only click on "Open Form3" from the mainmenu of Form1 I get an error:-

An unhandled exception of type 'System.OutOfMemoryException' occurred in
system.windows.forms.dll

Additional information: Error creating window handle.

If I edit out the "TextBox1.Text = CallingForm.Label1.Text" statement on
Form2 all is again OK but I can not pass the variable.

Any ideas on how to open Form3 (obviously without the text!)?

Cheers

Peter.

Nov 21 '05 #1
2 1353
Peter,

Assuming from your code that Form3 is a child from Form1 do you need to open
it as a child from form1 and not from form2

For that are in the childs the properties MDIParent and in the parent the
MDIChildren

http://msdn.microsoft.com/library/de...ldrentopic.asp

You need those to do what you want.

You have first to find the index of your form3 in form2

In form2 you work with.

me.mdiparent.mdichildren

I hope this helps,

Cor
Nov 21 '05 #2
Cor,

You are correct in saying that Form3 is a child of Form1. If I do not
reference form3 to form2 (via the TextBox1.Text = CallingForm.Label1.Text
statement) form3 opens from form1 without any problems.

Form2, a child in form1, opens form3 still with form3 as a child in form1. I
am a bit confused about why I need to find the index of form2 when opening
form3 directly from form1.

Thanks

Peter.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Peter,

Assuming from your code that Form3 is a child from Form1 do you need to
open it as a child from form1 and not from form2

For that are in the childs the properties MDIParent and in the parent the
MDIChildren

http://msdn.microsoft.com/library/de...ldrentopic.asp

You need those to do what you want.

You have first to find the index of your form3 in form2

In form2 you work with.

me.mdiparent.mdichildren

I hope this helps,

Cor

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: yup | last post by:
I was wondering if you know a way to have, let's say, you would click on a menu bar item (where something like file, edit, format, help options are on Microsoft Word) and instead of opening a...
4
by: LCAdeveloper | last post by:
Help! Another newbie question I'm afraid. I have a toolbar on an MDI form, which I can control OK to produce a child form. When the child form is active, the appropriate MDI parent form toolbar...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
10
by: Goran Djuranovic | last post by:
Hi all, Does anyone know how to declare a variable in a class to be accessible ONLY from a classes instantiated within that class? For example: ************* CODE ***************** Public...
5
by: vul | last post by:
I have an MDI application with a ListBar on the left side of MDI form. All child forms are displayed inside of the client area of MDI form. Now I need to display a third form from a child and...
4
by: Steve Hershoff | last post by:
I have two UserControls I'd like to have talk to each other. One of them is contained within the other, in a parent/child relationship. The child control is loaded dynamically (it's declared as a...
4
by: Richard Lewis Haggard | last post by:
What is the mechanism by which a child window can notify its parent that it has been clicked on? -- Richard Lewis Haggard www.Haggard-And-Associates.com
4
by: Harlequin | last post by:
I have a question concerning the need to trigger events within a "child" subform which is itself enbedded within a master "parent" form and which is accessible via a tab in the parent form. Becuase...
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.