PC Review


Reply
Thread Tools Rate Thread

How can i loop through mdi child forms? Code please

 
 
Edwinah63
Guest
Posts: n/a
 
      18th Aug 2004
Hi Everyone,

in vb6 i was able to execute the following code and it would close the
children is the reverse order they were opened eg the last child
opened was the first child to close.

in mdiparent i had this code

i = Forms.Count - 1
Do Until i = 0
If Forms(i).Name <> "mdiMain" Then Unload(Forms(i))
i = i - 1
Loop

in the queryunload event of each child form i would prompt the user
if msgbox(msg) = vbyes then
'clean up objects etc
else
cancel = true
end if

setting cancel to true, seemed to kill the loop in the code in
mdiParent.

i have tried using in the new vbnet mdiParent form:

Dim f As Form
For Each f In Me.MdiChildren
if Not IsNothing(f) Then f.Close()

'somehow capture if the user has
'cancelled the close of a child form and exit loop

Next

in the closing event of each child
if msgbox(msg) = vbyes then
'clean up objects etc
else
e.cancel = true
end if

the forms seem to close in the order they are opened, however i would
prefer them to close in reverse order.

also, how can i capture if a user has canceled the form close event?
is there something already existing that i can check, i am not a fan
of setting global flags.

ideally, i would like the vb.net code equivalent of my old vb6 code

many thanks

Edwinah63
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      18th Aug 2004
Edwinah,

What is that sentence "clean up objects", when you have done everything as
it should be, than that is done by the framework. That is one of the reasons
why it is managed code.

Maybe this helps already something?

Cor


 
Reply With Quote
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      18th Aug 2004
Hi,



Try something like this.



Dim f() As Form = Me.MdiChildren

For x As Integer = f.GetUpperBound(0) To 0 Step -1

f(x).Close()

Next



Ken

-------------------

"Edwinah63" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hi Everyone,

in vb6 i was able to execute the following code and it would close the
children is the reverse order they were opened eg the last child
opened was the first child to close.

in mdiparent i had this code

i = Forms.Count - 1
Do Until i = 0
If Forms(i).Name <> "mdiMain" Then Unload(Forms(i))
i = i - 1
Loop

in the queryunload event of each child form i would prompt the user
if msgbox(msg) = vbyes then
'clean up objects etc
else
cancel = true
end if

setting cancel to true, seemed to kill the loop in the code in
mdiParent.

i have tried using in the new vbnet mdiParent form:

Dim f As Form
For Each f In Me.MdiChildren
if Not IsNothing(f) Then f.Close()

'somehow capture if the user has
'cancelled the close of a child form and exit loop

Next

in the closing event of each child
if msgbox(msg) = vbyes then
'clean up objects etc
else
e.cancel = true
end if

the forms seem to close in the order they are opened, however i would
prefer them to close in reverse order.

also, how can i capture if a user has canceled the form close event?
is there something already existing that i can check, i am not a fan
of setting global flags.

ideally, i would like the vb.net code equivalent of my old vb6 code

many thanks

Edwinah63


 
Reply With Quote
 
Edwinah63
Guest
Posts: n/a
 
      19th Aug 2004
> What is that sentence "clean up objects"

sorry Cor, this is just my own user made objects, not system objects
etc i prefer to explicitly extinguish user made objects rather than
relying on them to just go out of scope.

However, does anyone know how i can capture if the user has cancelled
the close of a child form?

all thoughts appreciated. many thanks to Ken for his code.

Edwinah63
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      19th Aug 2004
Edwinah,

It should not be necassary however maybe you can use this.

\\\
For Each frm As Form In Me.MdiChildren
' do cleanup
Next
///

I hope this helps?

Cor

">
> sorry Cor, this is just my own user made objects, not system objects
> etc i prefer to explicitly extinguish user made objects rather than
> relying on them to just go out of scope.
>
> However, does anyone know how i can capture if the user has cancelled
> the close of a child form?
>
> all thoughts appreciated. many thanks to Ken for his code.
>
> Edwinah63



 
Reply With Quote
 
Edwinah63
Guest
Posts: n/a
 
      23rd Aug 2004
Does anyone know how to capture if a user has cancelled the close event on a form?

i am not sure that question was answered.

ta
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      23rd Aug 2004
Did you see my answer?

When a form is in that loop it is not closed.

Cor


 
Reply With Quote
 
Edwinah63
Guest
Posts: n/a
 
      26th Aug 2004
"Cor Ligthert" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Did you see my answer?
>
> When a form is in that loop it is not closed.
>
> Cor


Hi Cor,

i did see your answer:

For Each frm As Form In Me.MdiChildren
' do cleanup
Next

but i am not sure it is applicable here.


i am currently using Ken's code in my app:

Dim f() As Form = Me.MdiChildren

For x As Integer = f.GetUpperBound(0) To 0 Step -1

f(x).Close()

Next


What i am after is a way of stopping the loop if a user cancels an
explicit close eg:

Dim f() As Form = Me.MdiChildren

For x As Integer = f.GetUpperBound(0) To 0 Step -1

f(x).Close()

if UserCancelsChildFormClose then
'exit for or do something else
end if

Next

i can achieve this by setting a global varible but i was wondering if
there is something native in the forms that i can detect (a cancel
event???).

many thanks

Edwinah63
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      26th Aug 2004
Edwinah,

In every close event from a form is the e.cancel, you can set that to true
or false and I am never sure if it is e.cancel = true means cancel the close
operation or that it means e.cancel is true close the class, so try it
yourself. (I thought it was the first)

Than you can check in that close event if it is done in the correct way or
that the user has pushed the close X in the top.

To get the main form in a mdichild is
me.parent.xxxxx

I hope this helps?

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Child form code access to parent code object =?Utf-8?B?UmF5IE1pdGNoZWxs?= Microsoft C# .NET 1 1st May 2007 05:14 AM
how to Access the Child Node in XML Which is given in loop through VB safs Microsoft Outlook Contacts 1 14th Oct 2006 08:27 PM
mdi and child forms - view tabcontrol in child form andreas Microsoft VB .NET 1 23rd Jun 2004 04:27 AM
Newbie: Code to loop through all forms CJM Microsoft Access 6 3rd Jun 2004 10:48 AM
Toolbar sample code for MDI child forms Bill Gates Microsoft C# .NET 0 25th Nov 2003 11:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:03 PM.