473,626 Members | 3,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s) Handles MenuItem1.Click
Dim NewMDIChild As New Form2
NewMDIChild.Mdi Parent = Me
NewMDIChild.Sho w()
End Sub

Private Sub MenuItem2_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MenuItem2.Click
Dim NewMDIChild As New Form3
NewMDIChild.Mdi Parent = Me
NewMDIChild.Sho w()
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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Label1.Text = "Text to Send"
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim NewMDIChild As New Form3
Dim ShowForm3 = New Form3(Me)
ShowForm3.MdiPa rent = 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()
InitializeCompo nent()
CallingForm = newCallingForm
End Sub

Private Sub Form3_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
TextBox1.Text = CallingForm.Lab el1.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.OutOfMe moryException' occurred in
system.windows. forms.dll

Additional information: Error creating window handle.

If I edit out the "TextBox1.T ext = CallingForm.Lab el1.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 1360
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.md ichildren

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.Lab el1.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******** ********@TK2MSF TNGP09.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.md ichildren

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
1749
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 dialog box it would "switch" to another page (within the program) and maintain the same menu bar as before. For example, in Quicken I would click on "Finances" then "Account List" and a new page would open under the existing menu bar. It wouldn't...
4
2765
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 button properties are set as follows: .pushed=true and .enabled=false. My problem is how do I set the reverse conditions when I close this child form? I have tried putting (in the Exit button click event) Toolbar1.Buttons(6).Pushed=False...
5
3531
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 do the update the changed parentid in the child table fails to change. No error is given its just that the change is not written to the Database. When I step through the records for the child table the one I would expect to be changed has a row...
10
19602
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 Class Parent '*** HOW TO DECLARE IT *** Dim Age As String = "1/1/2000"
5
4454
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 center it related to the calling Child form. I cannot find the way to do that. Any help please Al
4
2060
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 WebControls.Placeholder) in the parent through a call to LoadControl(). I'm using events to communicate between them. The parent will fire an event, and if the child is listening it will do something. That's the idea at least.
4
3559
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
6046
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 this is all very difficult to explain in words, please bear with me as I endevour to explain what it is I am trying to do. It would be helpful if I could attach a graphics file to this posting that would help explain what it is I'm trying to achieve...
21
3334
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 a zipcode that is unknown this form will open. I don't want users to modify any of this customers data until they close the zipcode form. Normally this can accomplished using a modal form, however this prevents me from opening a new copy of...
0
8262
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8701
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8502
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7192
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.