Sep 21, 2013 The ErrorProvider alerts the user that something is wrong. In this example I will use a Display Warning icon, Wrong icon (when an incorrect expression is entereded) or a Tick icon depending upon the data entered in the text box so that the user can determine that data entered is correct or incorrect. Let's Begin as in the following: 1.
The Windows Forms ErrorProvider
component is used to show the user in a non-intrusive way that something is wrong. It is typically used in conjunction with validating user input on a form, or displaying errors within a dataset.
The ErrorProvider is a Winforms control. There is no equivalent in WPF. But you will still be able to find in in visual studio 2008 if you create a win forms project. You might want to take a look at this article on error validation in WPF. A DataGridViewCell has an ErrorText property. What you do is, you handle the OnCellValidating event and if fails validation, you set the error text property, and you get that red error icon to show up in the cell. Here's some pseudo code.

The Windows Forms ErrorProvider component allows you to show the user in a non-intrusive way that something is wrong.It is typically used in conjunction with validating user input on a form, or displaying errors within a dataset. To run this example, paste the following code into a form containing a TextBox named TextBox1, an OpenFileDialog named OpenFileDialog1, a button named Button1, and an ErrorProvider named ErrorProvider1. Ensure all events are associated with their event handlers.
In This Section
ErrorProvider Component Overview
Explains what this component is and its key features and properties.
How to: Display Error Icons for Form Validation with the Windows Forms ErrorProvider Component
Gives directions for validating user input with an error provider component.
How to: View Errors Within a DataSet with the Windows Forms ErrorProvider Component
Gives directions for using an error provider component to display data errors.
Reference
ErrorProvider
Describes this class and has links to all its members.
Related Sections
Controls to Use on Windows Forms
Provides a complete list of Windows Forms controls, with links to information on their use.
- Details
- Written by David Corrales
- Last Updated: 15 June 2016
- Created: 11 August 2011
- Hits: 10585
Provides a user interface for indicating that a control on a form has an error associated with it.
Default Event: N/A
Why use a ErrorProvider control?
Use the ErrorProvider if you want to notify the user that there is an input error by flashing an icon next to the input control. You can use a single ErrorProvider for multiple controls. In the case where you wish to display different icons or styles, you will need to use multiple ErrorProvider controls.
Important Properties:
Icon
Use this property to change the icon used to indicate an error.
Default Icon:
BlinkRate
This property controls the rate in milliseconds at which the error icon blinks.
Use this property to increase or decrease the blink rate of the icon. Note: 1000 milliseconds = 1 sec.
Default Value: 250
BlinkStyle
This property controls whether the error icon blinks when an error is set.
Values (Default: BlinkIfDifferentError):
BlinkIfDifferentError
Blinks when the icon is already displayed and a new error string is set for the control.
AlwaysBlink
Always blinks when the error icon is first displayed, or when an error description string is set for the control and the error icon is already displayed.
NeverBlink
Never blinks the error icon.
Important Methods:
SetError
This method sets the error description string for the specified control.
Use the SetError method to display the error icon next to the target control and display a specified error message when the user hovers the mouse over the error icon. To clear an error message, pass an empty string to the method, using the same control as a parameter.
Example use of the SetError method when validating a TextBox:
The ErrorProvider displayed in the form:
SetIconAlignment
This method sets the location where the error icon should be placed in relation to the control.
Note: You have to set the alignment for each individual control.
Note: You can set also set the Icon Alignment in the designer by setting the target control’s “IconAlignment on errorprovider1” property.
An example use of the SetIconAlignment method where the error Icon is set on the left side of the TextBox control:
The resulting form:
The second parameter of the method accepts an enum of type [System.Windows.Forms.ErrorIconAlignment]. Since PowerShell allows you to express enum values as strings, you can shorten the call by just passing the name of the ErrorIconAlignment value:
Default Alignment: MiddleRight
ErrorIconAlignment Values:
TopLeft
The icon appears aligned with the top of the control and to the left of the control.
TopRight
The icon appears aligned with the top of the control and to the right of the control.
Errorprovider In C# Windows Application
MiddleLeft
The icon appears aligned with the middle of the control and the left of the control.
MiddleRight
The icon appears aligned with the middle of the control and the right of the control.
BottomLeft
The icon appears aligned with the bottom of the control and the left of the control.
BottomRight
The icon appears aligned with the bottom of the control and the right of the control.
SetIconPadding
Errorprovider C#
Sets the amount of extra space left between the specified control and the error icon.
Note: You have to set the padding for each individual control.
Errorprovider C#
Note: You can set also set the Icon Padding in the designer by setting the target control’s “IconPadding on errorprovider1” property.
ErrorProvider with padding set to 1:
Errorprovider Set Error
ErrorProvider with the padding set to 10:
Download the ErrorProvider Sample.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.
