472,345 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

Mdi Form Validating

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

Jul 12 '06 #1
4 2332
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

ea********@gmail.com 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
Jul 13 '06 #2
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

ea********@gmail.com 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

Jul 13 '06 #3
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

Jul 13 '06 #4
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
Jul 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have a couple of controls on the form, some of them has the validating and validated. In validating, i run the test and if not...
1
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have written a simple validating event for a couple of textbox's on a form. They validate just fine when leaving the form, now for the...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of...
19
by: zacks | last post by:
I have a .NET 2.0 MDI application where the child form has a Tab Control. Each of the Tab in the Tab Control has a Validating event to handle what...
3
by: mtczx232 | last post by:
I have TabControls that Hold Forms on his TabPges (this make me easy to give ability to Designing each form in his IDE window). When form x is in...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.