Results 1 to 2 of 2

Thread: Error provider???

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Error provider???

    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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Error provider???

    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:
    1. Private Sub surnameText_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles surnameText.TextChanged
    2.     Me.SetSurnameError()
    3. End Sub
    4.  
    5. Private Sub SetSurnameError()
    6.     If Me.RecordIsLoaded AndAlso _
    7.        Me.surnameText.Text.Trim() = String.Empty Then
    8.         Me.errorIndicator.SetError(Me.surnameText, String.Format(SURNAME_ERROR, Me.surnameLabel.Text.TrimEnd(":"c)))
    9.     Else
    10.         Me.errorIndicator.SetError(Me.surnameText, Nothing)
    11.     End If
    12.  
    13.     Me.OnDataStateUpdated()
    14. End Sub
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width