Question : How can I cancel (or clear) validation events on a Windows form

Here's a simplified scenario of my problem.  I have many text boxes on the form, but for this example I have pretended to have just two.

Assume I have 2 textboxes and a button on a form which I will call btnCancel.
Textbox 1 has no validation.
Textbox 2 has validation and requires an entry.  On TextBox 2's validation event if there is no entry I show a message and set e.Cancel to true.

Now I want to allow the user to press the ESC key to Escape out of field 2 after receiving the message and reset the fields to default values again and focus back on field 1.

I have added code for ProcessDialogKey as shown below.  If the user presses the ESC key the btnCancel_Click event is performed where I check certain conditions and either close the form OR reset the form details and position back onto TextBox 1.

If the conditions are met for closing, the form closes fine.  Otherwise the form is correctly reset and the cursor is position back onto field 1. BUT,  as soon as I try to Exit field 1, Field 2 validation Event fires again and I cannot get out of this loop.

Is there a way to clear the validation 'stack' or process?

Here is the sample ProcessDialogKey code:

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                AutoValidate = AutoValidate.Disable;
                btnCancel.PerformClick();
                AutoValidate = AutoValidate.Inherit;
                return true;
            }

            if (keyData == Keys.Enter)
            {
                return base.ProcessDialogKey(Keys.Tab);
            }

            return base.ProcessDialogKey(keyData);
        }

Answer : How can I cancel (or clear) validation events on a Windows form

I found a solution for you, but it requires a little bit of elbow grease.

here goes:

1- Download Title manager plugin for joomla (this workaround is actually a hack of this plugin)

http://extensions.joomla.org/extensions/site-management/seo-a-metadata/3521?qh=YTo5OntpOjA7czo0OiJzaXRlIjtpOjE7czo1OiJzaXRlcyI7aToyO3M6NDoibmFtZSI7aTozO3M6NToibmFtZWQiO2k6NDtzOjU6Im5hbWVzIjtpOjU7czo2OiJuYW1pbmciO2k6NjtzOjY6Im5hbWVseSI7aTo3O3M6NzoibWFuYWdlciI7aTo4O3M6OToic2l0ZSBuYW1lIjt9

2-  Install the plugin

3- Don't forget to activate the plugin...  no configuration necessary

4- Replace the file plugins/system/titlemanager.php with the one attached in here

5- Enjoy
Random Solutions  
 
programming4us programming4us