How to reload MDI Child

  • Thread starter Thread starter Tony Diggs
  • Start date Start date
T

Tony Diggs

Hi VB.Net Gurus.

Initial MDI Child form loads fine.
exp.

Dim objChild2 As New Form2()
objChild2.MdiParent = Me
objChild2.Show()


MDI Child unloads just fine.
Exp.
If e.Button Is tbbExit Then
'' Me.Close()
Me.Hide()

rs.Close()
cn.Close()

End If


The MDI Child reload does not reload into the parent form.
It reloads outside the parent form.
exp.

Dim oForm As New Form2()
oForm.MdiParent = Me.ActiveMdiChild
oForm.Show()

Regards,

Tony

Why not use this again?
Dim oForm As New Form2()
oForm.MdiParent = Me.ActiveMdiChild
oForm.Show()

Because loaded by another form's label link yields this;

Additional information: The form that was specified
to be the MdiParent for this form is not an MdiContainer.

Tony
 
Int he first part which works you have

objChild2.MdiParent = Me

In the second part, which doesn't work, you have

oForm.MdiParent = Me.ActiveMdiChild

Why would you be trying to set the MdiParent to Me.ActiveMdiChild?

Bob
 
Tony

Go to the proerties of the form in question and look
for 'isMDIContainer' set this property as true then use
the code:

\\\
Dim oForm As New Form2()
oForm.MdiParent = Me.ActiveMdiChild
oForm.Show()
///

to call another instance of the child from anywhere in
the form that you just made a MDI container
 
Now, the first instance won't load.

Err. message;

Additional information: A form can't be both an MDI child and MDI
parent.

Also, any subsequent forms that I want to load from the menu form,
load successfully, but do not load into the parent form next to the
menu form. It loads outside the parent form. I'm trying to get all forms
to load into the parent form as in VB 6.0

Tony
 
VB.Net User
Answer from Microsoft:
Dim oForm As New Form2()
oForm.MdiParent = Me.ParentForm
oForm.Show()

Tony
 
This is how I am handling MDI child forms that should only have a single
instance.

Private Sub MenuItemCustomerMaintenance_Click(ByVal sender As System.Object,
_

ByVal e As System.EventArgs) _

Handles MenuItemCustomerMaintenance.Click

Static afrm As FormCustomerMaintenance

If afrm Is Nothing OrElse afrm.IsDisposed Then

afrm = New FormCustomerMaintenance

afrm.MdiParent = Me

End If

afrm.Show()

afrm.BringToFront()

End Sub

"tonyd" <

(e-mail address removed)> wrote in message
 
"If afrm Is Nothing OrElse afrm.IsDisposed Then"

Here's a problem. Don't use OrElse. Use Or.

Bob
 
I'm new to .Net, but a longtime VB6 programmer, I had tried that at first,
it didn't work.

Bob, can you please explain why it is a problem?
 
Bob said:
"If afrm Is Nothing OrElse afrm.IsDisposed Then"

Here's a problem. Don't use OrElse. Use Or.

OrElse must be used because Or leads to a NullReferenceException if afrm is
nothing.
 
Here's a problem. Don't use OrElse. Use Or.

Whoops never mind about that, I misread the code.

Er, your code looks fine. Here is a simple working example of what I think
you're after, though I'm not sure you need it. If it doesn't help, you should
post code that reproduces the problem you're having.

Bob

Module Main

Public Sub Main()
Dim ParentForm As New MDIParentForm
ParentForm.WindowState = FormWindowState.Maximized
ParentForm.ShowDialog()
End Sub

Public Class MDIParentForm
Inherits Form
Public Sub New()
Me.IsMdiContainer = True
Me.Menu = New MainMenu
Me.Menu.MenuItems.Add("show child form", _
AddressOf mnuShowChildClicked)
End Sub
Private Sub mnuShowChildClicked( _
ByVal sender As Object, ByVal e As EventArgs)
Static ChildForm As Form
If ChildForm Is Nothing OrElse ChildForm.IsDisposed Then
ChildForm = New Form
ChildForm.MdiParent = Me
End If
ChildForm.Show()
ChildForm.BringToFront()
End Sub
End Class

End Module
 
Bob,
"If afrm Is Nothing OrElse afrm.IsDisposed Then"
Here's a problem. Don't use OrElse. Use Or.
Use "Or" if you want to ensure a NullReferenceException! :-|

Remember that "OrElse" is short circuited where as "Or" is not. Which means
that if afrm is Nothing, OrElse will not attempt to call afrm.IsDisposed,
avoiding the NullReferenceException.

However!! Or will attempt to call afrm.IsDisposed whether afrm is Nothing or
not.

Hope this helps
Jay
 
Jim,
I would expect your method to work.

Are you having a problem with your method or did you offer it as a solution
to the OP?

Bob's advice is not very sound, as it will ensure a NullReferenceException
when afrm is Nothing, where as your sample will correctly avoid the
NullReferenceException via the OrElse operator.

I don't see any problems with your sample, which is why I am asking if you
had a problem with it.

Hope this helps
Jay
 
Thank you, yes, everybody, I MADE A MISTAKE. Read my later post. See it? Posted
before this one? I'M SORRY. Sheesh. >:(

Bob
 
* "Bob said:
"If afrm Is Nothing OrElse afrm.IsDisposed Then"

Here's a problem. Don't use OrElse. Use Or.

Why?

Are you sure about the difference between 'Or' and 'OrElse'?
 
Hi Herfried,

I know a Hamster has little eyes, but Bob did make an excuus about his
misreading at our time 17:13 and 17:47 so this is a little bit much mustard
after dinner.

:-)))

Cor
 
* "Cor said:
I know a Hamster has little eyes, but Bob did make an excuus about his
misreading at our time 17:13 and 17:47 so this is a little bit much mustard
after dinner.

OE shows the complete thread, my other newsreader doesn't.

:-(((
 
Jay, sorry for the late reply, been busy recovering from the Thanksgiving
day holiday.

I was offering it as a solution, I had no problem with it. I just didn't
understand the Or/OrElse issue that Bob raised.

I see that others responded appropriately :)
 
Back
Top