PC Review


Reply
Thread Tools Rate Thread

Mdi Form Validating

 
 
easoftware@gmail.com
Guest
Posts: n/a
 
      12th Jul 2006
I am using VS .Net 2003 and VB. I have an app with one parent and two
Mdi child forms. I need to validate data in the Mdi form. The
Form.Validating event works when I try to close a Mdi form, but not
when I try to switch form one Mdi form to the other. I tried to add
code to MdiForm1's Deactivate event:

Private Sub MidForm1_Deactivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Deactivate

Dim TempE As System.ComponentModel.CancelEventArgs
TempE.Cancel = False
MdiForm1_Validating(sender, TempE)
If TempE.Cancel Then
MdiForm1_Activated(sender, e)
End If
End Sub

but when MdiForm2 tries to load, the program crashes:

An unhandled exception of type 'System.OutOfMemoryException' occurred
in system.windows.forms.dll

Additional information: Error creating window handle.

How can I keep the focus in MdiForm1 when the user wants to change
forms and the data in MdiForm1 is not valid?

Thanks
Eric

 
Reply With Quote
 
 
 
 
tomb
Guest
Posts: n/a
 
      13th Jul 2006
I am guessing you mean when you switch from one child form to the
other. Why don't you try validating in the OnLostFocus override event?
Then you can regain focus.

T

(E-Mail Removed) wrote:

>I am using VS .Net 2003 and VB. I have an app with one parent and two
>Mdi child forms. I need to validate data in the Mdi form. The
>Form.Validating event works when I try to close a Mdi form, but not
>when I try to switch form one Mdi form to the other. I tried to add
>code to MdiForm1's Deactivate event:
>
> Private Sub MidForm1_Deactivate(ByVal sender As Object, ByVal e As
>System.EventArgs) Handles MyBase.Deactivate
>
> Dim TempE As System.ComponentModel.CancelEventArgs
> TempE.Cancel = False
> MdiForm1_Validating(sender, TempE)
> If TempE.Cancel Then
> MdiForm1_Activated(sender, e)
> End If
> End Sub
>
>but when MdiForm2 tries to load, the program crashes:
>
>An unhandled exception of type 'System.OutOfMemoryException' occurred
>in system.windows.forms.dll
>
>Additional information: Error creating window handle.
>
>How can I keep the focus in MdiForm1 when the user wants to change
>forms and the data in MdiForm1 is not valid?
>
>Thanks
>Eric
>
>
>

 
Reply With Quote
 
 
 
 
easoftware@gmail.com
Guest
Posts: n/a
 
      13th Jul 2006
I would like the validating to test before the other MDI form gets
focus. Per VB documentation, the event order is:

1) Enter (Activated for Forms)
2) Got Focus
3) Leave (Deactivated for Forms)
4) Validating
5) Validated
6) Lost Focus

so, if the validating is in Lost Focus, the other form gets displayed
before the not valid error message can be shown. I would like to keep
the user in the form that is being validated.

tomb wrote:
> I am guessing you mean when you switch from one child form to the
> other. Why don't you try validating in the OnLostFocus override event?
> Then you can regain focus.
>
> T
>
> (E-Mail Removed) wrote:
>
> >I am using VS .Net 2003 and VB. I have an app with one parent and two
> >Mdi child forms. I need to validate data in the Mdi form. The
> >Form.Validating event works when I try to close a Mdi form, but not
> >when I try to switch form one Mdi form to the other. I tried to add
> >code to MdiForm1's Deactivate event:
> >
> > Private Sub MidForm1_Deactivate(ByVal sender As Object, ByVal e As
> >System.EventArgs) Handles MyBase.Deactivate
> >
> > Dim TempE As System.ComponentModel.CancelEventArgs
> > TempE.Cancel = False
> > MdiForm1_Validating(sender, TempE)
> > If TempE.Cancel Then
> > MdiForm1_Activated(sender, e)
> > End If
> > End Sub
> >
> >but when MdiForm2 tries to load, the program crashes:
> >
> >An unhandled exception of type 'System.OutOfMemoryException' occurred
> >in system.windows.forms.dll
> >
> >Additional information: Error creating window handle.
> >
> >How can I keep the focus in MdiForm1 when the user wants to change
> >forms and the data in MdiForm1 is not valid?
> >
> >Thanks
> >Eric
> >
> >
> >


 
Reply With Quote
 
Barry
Guest
Posts: n/a
 
      13th Jul 2006
Hi,

Maybe you could check that ChildForm1 is valid in the ChildForm2
GotFocus. If it is valid then no problems - if it isn't switch back to
ChildForm1?

I haven't looked in to this properly - just an idea....

HTH

Barry

 
Reply With Quote
 
easoftware@gmail.com
Guest
Posts: n/a
 
      14th Jul 2006
Thanks for the help, but the problem with this approach is the number
of forms. In my example, there are only two, but my app will have
more. SO... I would have to check if Form#x is open, and it it is, is
the user editing, and if editing then validate. I would need to have
this code for every MDI form that could be open and editing data. I
would also have to do this in each form's GotFocus event. It would be
much cleaner to do the validation in the form with the data being
edited.

Barry wrote:
> Hi,
>
> Maybe you could check that ChildForm1 is valid in the ChildForm2
> GotFocus. If it is valid then no problems - if it isn't switch back to
> ChildForm1?
>
> I haven't looked in to this properly - just an idea....
>
> HTH
>
> Barry


 
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
MDI question - how to call other MDI child forms from a MDI chilid form? Robert Johnson Microsoft VB .NET 2 21st Jun 2007 11:27 PM
acess a control in a MDI parrent form from a MDI child form authorking Microsoft C# .NET 1 2nd Feb 2005 12:20 PM
Mdi Child Form in Mdi Parent Form Sylvain Microsoft VC .NET 1 7th Jan 2004 07:49 PM
A problem to opem MDI child form from another MDI child form Herfried K. Wagner [MVP] Microsoft VB .NET 2 26th Dec 2003 10:30 PM
Is there ANY way to have an MDI form INSIDE another MDI form? KVullo Microsoft Dot NET Framework Forms 3 23rd Oct 2003 08:32 PM


Features
 

Advertising
 

Newsgroups
 


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