I got an mdi form and i want to know how to close mdi children and not close the parent.
Printable View
I got an mdi form and i want to know how to close mdi children and not close the parent.
MDI children forms are in the parent's OwnedForms array (or collection) so you could close them from there or from themselves with the usual Me.Close() otherwise in the parent it'd be something like Me.OwnedForms(0).Close().
Owned forms only refers to forms that are in the owned forms array which will only inlcude mdi children if they are not currently open. To access mdi children regardless of weather they are open or not you must use the mdichildren property. I use the following code to close all open children of an mdi parent.
When you close each form the next one takes its place as element 0 and gets closed the next time through the loop until there are no more to close at which point the catch statment exits the loop for you.Code:Try
Do While True
Me.MdiChildren(0).Close()
Loop
Catch
'this exits the loop when you reach the end of the array
End Try