OK i was just wondering if anyone had any good used for the Error provider. I never use and people i have asked have never used it. so i was wondering what some uses were? :eek2: :eek2: :eek2:
Printable View
OK i was just wondering if anyone had any good used for the Error provider. I never use and people i have asked have never used it. so i was wondering what some uses were? :eek2: :eek2: :eek2:
I've used them numerous times. They are a very unobtrusive way to indicate to the user that they need to do something to fix an issue. For instance, if I have a form with multiple text fields and some are required to be populated, I'll use an ErrorProvider to indicate that the ones that are empty must be filled. I then handle the TextChanged event of the fields and if the field is not empty I clear the error and if it is empty I set the error. I would then disable the Save button as long as there were any errors.
The ErrorProvider has a number of advantages over other methods. If you pop up a MessageBox then as soon as the user dismisses it the error message is gone, whereas with the ErrorProvider they can mouse over the icon whenever they want. Also, if you use the Validating event of a control then the user can't leave a field until the error is fixed. Using the ErrorProvider allows the user to leave the field while it is in error, which may be preferable in many cases.
Here's an example from my own code:VB Code:
Private Sub surnameText_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles surnameText.TextChanged Me.SetSurnameError() End Sub Private Sub SetSurnameError() If Me.RecordIsLoaded AndAlso _ Me.surnameText.Text.Trim() = String.Empty Then Me.errorIndicator.SetError(Me.surnameText, String.Format(SURNAME_ERROR, Me.surnameLabel.Text.TrimEnd(":"c))) Else Me.errorIndicator.SetError(Me.surnameText, Nothing) End If Me.OnDataStateUpdated() End Sub