Skip to content

ErrorProvider extend with HasErrors property #5912

Description

@tugibaev

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	
	}
}

Metadata

Metadata

Assignees

Labels

api-approved(4) API was approved in API review, it can be implementedapi-suggestion(1) Early API idea and discussion, it is NOT ready for implementationarea-ErrorProviderIssues relating to ErrorProviderhelp wantedGood issue for external contributors

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions