ErrorProviders

S

stuart.d.jones

Hi,

I've set up an errorprovider on a form, but I have the following
problem.

I've got a button for the user to cancel the operation, but if there's
an error in any of my textboxes, the cancel button doesn't work, and
the user can't leave the textbox.

Is there any way around this? Presently I'm validating controls in
their OnValidating events, and setting e.cancel = true if there's a
problem, along with using SetError to get the errorprovider to do its
work. In the OnValidated event, I'm clearing the error messages.

The functionality of this is 99% how I want it - I just need the user
to be able to cancel!

Any help greatly appreciated!

Stu
 
T

Tim Scott

Stu,

Check out the Control.CausesValidation property--if you set it to true
on your cancel button, then the Validating event should be suppressed
when cancel is clicked, allowing the user to cancel out.

See
http://msdn.microsoft.com/library/d...owsformscontrolclasscausesvalidationtopic.asp

There is also this thread, about a similar topic:
http://groups.google.com/group/micr...read/thread/b04504033e1a9b52/8885e9e6203f8040
however, it seemed to work for me by setting CausesValidation to false
on the one control (instead of all of them). But my test was on a very
simple form.

Hope this helps,

-- Tim Scott
http://geekswithblogs.net/tscott
 
S

stuart.d.jones

Hi Tim,

Thanks - I had tried that, but you re-iterating that it was the way to
go made me think again.

The problem was that my button was in a group box. I'd set the
CausesValidation property of the button to false, but hadn't set the
property of the group box similarly - hence it was the group box
getting the focus that was causing validation.

Problem solved!

Cheers,

Stu
 
T

Tim Scott

Stu,

Ah, good catch. That may be why the other post said to set
CausesValidation to false on ALL controls--a brute force way to set the
parent control's CausesValidation.

That should probably be in the MSDN page about CausesValidation...

Thanks for the follow-up.
-- Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top