Solved

ErrorProvider Question

Posted on 2008-10-12
5
511 Views
Last Modified: 2012-05-05
Hi, I'm using VB 2005, WinForms. I have a question about the ErrorProvider Control. -- Lets assume I've used the ErrorProvider in my Form on 15 different Controls, so that I can validate the input of each Control (assume it all works well). I don't want to add a new record unless all the validations have passed my requirements. So, how do I assess whether there are any validation tests that have not yet been addressed. In other words, how can I tell that an ErrorProvider is still alerting my User that a problem exists with one of the Controls?

Is there some sort of ErrorProvider.Count property (which I know is not available) or something similar that I can use to determine if I still have problems that need to be addressed?

By the same token, I want to be able to know that if no problems exist, I can go ahead and perform my record insertion into my DataBase.

So, in essence, I'm looking for some sort of "flag" that the ErrorProvider is still alerting of errors on the Form.

Thanks,
Fulano
0
Comment
Question by:Mr_Fulano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 22700410
The Error Provider Component used on Windows Forms is a very useful way of displaying the errors on the form, however its missing one small piece of information; the number of errors that are currently on the form. This custom error provider fixes that problem and allows you, among other things, to check the number of errors on the form before performing some action. i.e. If Me.ErrorProvider.HasErrors = False then It's proved very useful in a project

Source: http://dotnetslackers.com/Community/blogs/dsmyth/archive/2007/10/12/custom-error-provider.aspx
Public Class ErrorProviderWithCount
Inherits System.Windows.Forms.ErrorProvider
 
Dim controlsWithErrors As New List(Of Windows.Forms.Control)
 
Public Sub New(ByVal components As System.ComponentModel.IContainer)
MyBase.New(components)
End Sub
 
Public Shadows Sub SetError(ByVal control As Windows.Forms.Control, ByVal value As String)
MyBase.SetError(control, value)
If String.IsNullOrEmpty(value) Then
If controlsWithErrors.Contains(control) = True Then
controlsWithErrors.Remove(control)
End If
Else
If controlsWithErrors.Contains(control) = False Then
controlsWithErrors.Add(control)
End If
End If
End Sub
 
Public ReadOnly Property Count() As Integer
Get
Return controlsWithErrors.Count
End Get
End Property
 
Public ReadOnly Property HasErrors() As Boolean
Get
Return controlsWithErrors.Count > 0
End Get
End Property

Open in new window

0
 

Author Comment

by:Mr_Fulano
ID: 22700457
Hi Dhaest, thanks for the code. It an interesting approach. However, I did some research after I posted the question and found that if I use the ErrorProvider.GetErrro(myControl).Length property I can determine if the control still has an error. So in a simple IF Statement, you would do:

If ErrorProvider.GetErrro(myControl).Length > 0 Then
.. do something like set a flag or provide a message to the User.
End If

The down side is you have to check the length of each control, but it works well without having to build a new control.

Regardless, thanks for the code, which is always useful.
Fulano
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22700461
>> The down side is you have to check the length of each control, but it works well without having to build a new control.

I also knew that, but suppose you have 30 different controls, you'll have a big if-statement :)
Anyway, glad to see it's solved
0
 

Author Comment

by:Mr_Fulano
ID: 22700466
Correction for the typo above. The code should read:

ErrorProvider.GetError(myControl).Length

GetError not GetErrro

: )
0
 

Author Comment

by:Mr_Fulano
ID: 22700470
Yes, I agree with you that the IF statement can get lengthy, but it does fast once you get started.

Thanks again,
Fulano
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Write to a printer using vb.net 9 57
MailAddress in vb 4 36
VB.NET Application Installation with sqlserver 8 45
Need help converting bitmap to image in VB.Net 8 44
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question