Closing a MDI Child from the MDI parent throws an exception

Closing a MDI Child from the MDI parent throws an exception

Post by dnZlbm » Wed, 20 Jul 2005 11:46:03


Hello:

In the closing event of the MDI Parent, I have the following routine:

While Me.MdiChildren.Length > 0
liCounter = Me.MdiChildren.Length
Me.MdiChildren(liCounter - 1).Close()
End While

When I do have a MI Child, the .Close statement throws an exception, "Object
reference not set to an instance of an object".

What am I doing wrong?

Venki
 
 
 

Closing a MDI Child from the MDI parent throws an exception

Post by Eric Morea » Wed, 20 Jul 2005 19:04:27

try this:

for each x as form in me.mdichildren
x.close
next

--


HTH

ic Moreau, MCSD, Visual Developer - Visual Basic MVP
( http://www.yqcomputer.com/ )
Conseiller Principal / Senior Consultant
Concept S2i inc. (www.s2i.com)

 
 
 

Closing a MDI Child from the MDI parent throws an exception

Post by C-Services » Wed, 20 Jul 2005 19:27:29


Try changing this line:
Me.MdiChildren(liCounter - 1).Close()
to
Me.MdiChildren(0).Close()


--
Rinze van Huizen
C-Services Holland b.v.
 
 
 

Closing a MDI Child from the MDI parent throws an exception

Post by dnZlbm » Wed, 20 Jul 2005 19:47:02

Eric:

It raises the same exception, "Run-time exception thrown :
System.NullReferenceException - Object reference not set to an instance of an
object."

I am stumped!

Venki
 
 
 

Closing a MDI Child from the MDI parent throws an exception

Post by dnZlbm » Wed, 20 Jul 2005 20:25:04

Eric:

I see the following sequence of events when I close the MDIParent Window:

1. It closes the MDI Child Frm, triggers the closing event of the MDIChild
form.
2. Then it triggers the MDI Parent's closing event. But Me.MIDChildren.Count
is still 1, even though the MDI Child form has already been closed.
3. This raised the exception.

Any more ideas?