Textbox validation, focus switching issue

Good morning,

I am working on a C# winform application that is using validation for the controls. The issue I'm having is that when a user clicks into a textbox and attempts to click out, the validation fires and re-focuses the control, basically the user cannot click out of the control to another control.

My desired result is to have ALL of the controls on the form validate when the user clicks the submit button. I would like to have the errorProvider icon appear next to the fields that are in error and allow the user to correct them as they see fit.

My question is, how do I setup a control to allow a user to click outside of it when there is an error. I'd like the user to have the ability to fill in the rest of the form and come back to the error on their own instead of being forced to deal with it immediately.

Thank you in advance for any help and advice,


The simplest way would be just to put all the validation in the Submit button handler, instead of having it in the controls.

The form has AutoValidate property, that can be set to allow focus change

The form property is "AutoValidate" and it affects all controls on the form. It's an enum; set it to System.Windows.Forms.AutoValidate.EnableAllowFocusChange to allow user to exit a control which failed validation, but still show the error icon which allows the user to pull up error tooltip.

The control "CausesValidation" property is a boolean. If it's true then the control raises the validation event which triggers the errorProvider. It it's false, everything gets bypassed, user can exit control, but there's no error icon or tooltip.

we have a validation function that returns bool if the form is valid and sets all the error providers on the form:

looks like this:

    private void OnSave()
        //do save

    public bool ValidateData()
        bool valid = true;
        if (this.defectStatusComboBox.SelectedIndex == -1)
            errorProvider.SetError(defectStatusComboBox, "This is a required feild.");
            valid = false;
        return valid;

Need Your Help

Manually set up Entity Framework's Table per type inheritance

c# asp.net-mvc entity-framework inheritance table-per-type

I have some existing tables and models that were set up manually, that is just relying on Entity's implicit associations. I have no edmx files or designers or mapping wizards.

Handling resource xml files

java android xml android-resources

I'm new to development and would like to clarify a couple of simple points,