473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 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 2452
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 successfull, bring up the errorprovider, and if successfull...
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 problem. If i click a button to begin execution, i...
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 Javascript form validation functions, but it...
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 it should do when the user changes tabs. But...
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 middle of Edit Data Mode, I going to prevent:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.