Link to home
Start Free TrialLog in
Avatar of MattHess
MattHess

asked on

Validation in MDI Application

In my MDI Application, I have an MDI Parent Form which contains two
Child Forms, childA and childB. childA has a TextBox which has an
Validating event Handler

When the Users enters some text into this TextBox which does not pass
the validating event, the Event Handler sets the Cancel Property of
the CancelEventArgs argument to TRUE. The Cursor cannot leave the
Texbox, which is excty what I want... but:

When the user clicks on another MDI Child (e.g. childB), childB comes
to front. The user can click on any Textbox on childB, he will not get
the cursor into the Textbox, because the Cursor is held back in
childA. The user thinks that the Application is not responding.

It would be a lot better if I could prevent the User from activating
childB as long as childA has Validation Errors.

I am looking for a "clean" solution of this problem.

Regards
Matthias
Avatar of arif_eqbal
arif_eqbal

Well there's a hitch here, if you keep him stuck on the textbox he will not be able to do anything else with your application, So there's no direct way of doing it. Anyway, What you can do is set the form where you have the TextBox to TopMost on the validating Event Handler in case the validation fails, and again set it back to normal if it passes the validation.

However the focus can still pass to the second child form but since this form will be topmost he can probably undersatand that he needs to finish that job first.

If you want to be still more strict you can send back the focus to this form on the MdiChildActivate event of the MDI or the Activate event of the second child form. You'll have to keep a reference as to which form is being validated, you can do that in a module level variable....


What about implementing the ChildA as a modal dialog? This lets the user know that he *must* finish with ChildA before he can do anything else.
Avatar of MattHess

ASKER

Hello everyone

Thanks for your comments and ideas. Here arem y thoughts:

"if you keep him stuck on the textbox he will not be able to do anything else with your application"
... I would only use the Validating / Validated mechanism for field level validation. It simply makes no sense to let the user enter '32-12-2004' into a date field, does it? The user would have to go back and change the date to something meaningful.

I tried the TopMost Property. Does not work at all with MDI (at least in my tests).

I also tried the MDIChildActivate event, but it did not work eighter.

Child A as a modal dialog is also not an option. We definitely want to stick with MDI.

Regards Matthias
ASKER CERTIFIED SOLUTION
Avatar of gregasm
gregasm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
http://www.dotnet247.com/247reference/msgs/53/268424.aspx

The keyword is "clean" solution for this problem, as you mentioned above.

I have found myself facing the same problem as you several times in the past, and of all my solutions, none of them are what I consider "clean"...