Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have the validating event on some of my text boxes on my windows form.

 

When I press a search button my controls clear and some of them are enabled and some are not. The problem I have is that I can do a search on one or all of the textboxes but if I click in a textbox and then change my mind on what I want to search for the validating event kicks in and I can't get out of it until I entry something into it.

 

Can I turn the validating event on and off when needed at run time

Posted

I think the "change of mind" aspect is virtually impossible to distinguish from an omitted entry. You probably shouldn't be using a validation control for this. Anyway, you can dynamically concatenate your search criteria and just omit those w/c have blank values.

 

But addressing the question, the workaround I'm using so far is to set CausesValidation = False for the control that shouldn't fire validation events (such as a Cancel button). The problem is if you close the form in the same event and the last control to have focus is a validating control, then the Validating event of that control will fire. So another workaround I did was to iterate thru Form.Controls and set CausesValidation of each control to False. Another option is setting a form-level flag in the Closing event of the form; in the Validating events, just eval this flag so that validations don't fire when the form is about to close.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...