Domanda

I am using an error provider on my windows form. On submit of the form, I need to check if there is some error present on the form. Can I get if there is a error present in the error provider.

È stato utile?

Soluzione

Write a Validate() method that returns false if it fails validation and execute it from SaveButton handler. You should perform re-validation of all controls of the form in this method. Continue Save only when Validate() returns true.

You could use ErrorProvider.GetError to get an error of a particular control on your form, but to get all errors on the entire form you would need to iterate over all controls that use that particular ErrorProvider instance on your form anyway.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top