Text field authentication, focus switching problem

Good morning,

I am working on a C # winform application that uses validation for controls. The problem I am facing is that when the user clicks on the text box and tries to click, the check activates and re-focuses the control, basically the user cannot click the control until another control.

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

My question is how to configure the control so that the user can click outside it when there is an error. I would like the user to be able to fill out the rest of the form and return to the error on their own, instead of having to immediately deal with it.

Thank you in advance for your help and advice,

+5
source share
5 answers

The easiest way is to simply put the entire check in the handler of the Submit button, instead of having it in the controls.

+2
source

The form has an AutoValidate property that can be set to change focus.

+24
source

- "AutoValidate", . ; System.Windows.Forms.AutoValidate.EnableAllowFocusChange, , , , .

"CausesValidation" boolean. , , errorProvider. , , , .

+5

, bool, :

looks like that:

    private void OnSave()
    {
      if(ValidateData())
      {
        //do save
      }
    }

    public bool ValidateData()
    {
        errorProvider.Clear();
        bool valid = true;
        if (this.defectStatusComboBox.SelectedIndex == -1)
        {
            errorProvider.SetError(defectStatusComboBox, "This is a required feild.");
            valid = false;
        }
        //etc...
        return valid;
     }
+2
source

There's a property (I think it's in the form) that allows you to move between fields when validation is not performed. I can’t remember what he called, but I think it was written quite descriptively.

-1
source

All Articles