Summary
ErrorProvider have a Clear() method which removes all errors on all linked controls. But no any property/method which can show errors are exists.
Rationale and Usage
Current version of ErrorProvider need to create boolean variable and set in on every SetError call to check errors are exists. It makes code less readable.
Proposed API
Add readonly property HasErrors:
namespace System.Windows.Forms {
public class ErrorProvider {
public bool HasErrors => this.items.Count > 0;
}
}
Examples
// err - ErrorProvider placed on form
private bool CheckData(){
err.Clear(); // Clears old error before new check
if (!File.Exists("C:\\abc.txt"))
err.SetError(txtFileName, "File not exists");
if (numValue.Value > 100)
err.SetError(numValue, "Can't be greater than 100 percent");
// ... other checks here...
return !err.HasErrors;
}
private void Save(){
// Check values before save
if (CheckData()){
//Do save
}
}
Summary
ErrorProviderhave aClear()method which removes all errors on all linked controls. But no any property/method which can show errors are exists.Rationale and Usage
Current version of
ErrorProviderneed to create boolean variable and set in on everySetErrorcall to check errors are exists. It makes code less readable.Proposed API
Add readonly property
HasErrors:Examples