Can't reference control in MDI window from modal window
This is wierd,
I have an MDI child form created. Now when I open a modal from this child form to change some properties, I get a system.nullreference exception. Yet in the VS IDE it seems I am referencing the control correctly...
i.e
Dim frmChild as frmChildWindow
frmChild.TextBox1.Text = "Hello"
The editor sees textbox1 as being a control that exists, so why when I try to set its text value does it give ma a NullReferenceException?
To see the problem I am having, run the app, then select
File - New Window
Then right click in the new window, and select properties. Now what will happen here is the child window textbox value should be updated with the value set in the properties window.
Actually, the first time I looked at MDI stuff was when you asked, I have been working with OOP for so long that figuring out the appropriate properties and methods to use was just a matter of glancing at the available list. I'm just glad I could help
A lot of this code creates circular references, Form1 has a reference to Form2 and Form2 has a reference to Form1. VB .NET is very good about cleaning up behind itself, but in a production system it is still a good idea to do a little housekeeping when you close an object.
When Form1 creates an instance of Form2 and shows it, and Form2 has it's reference back to Form1, when closing Form2, you should probably write something like this:
VB Code:
Private frmChildWindow As frmChild
Private Sub frmProperties_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmChildWindow = Me.Owner
End Sub
Private Sub frmProperties_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Pardon my ignorance but what is the difference between an Owned form and a Child form?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Depends on how the form was created, an owned form is a form that was created as a non-mdi child form, but has the creating form as it's owner, while a child form is created as an mdichild form and has an mdi form as it's mdiparent
And btw, I caught your little comment about the quick responses to spoiledkids posts, and I assure you it had nothing to do with her icon, if it even is a her...
I just have any responses to my posts sent to my yahoo email account and messenger notifies me when I receive a response
To me it looks as if the practical effect and usage is the same. I can't see anything in MSDN which helps on this.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
I assure you it isn't, if you create a form as an mdichild using code in the MDI container form and set the child forms mdiparent property to the MDI container form, it doesn't have an owner, it has an mdiparent. If on the other hand you were to create these same forms and not set the mdiparent property but use rather the MDI containers AddOwnedForms method for each of the new forms, they would not be contained in the MDI container form.