Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Using ErrorProvider
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

M O J O
Hi,

How do I check if an ErrorProvider has errors?

Take for example this code...

(err = ErrorProvider...)

Public Sub Test
If TextBox1.Text= "" Then
err.SetError(TextBox1, "Error1'.")
End If

If TextBox2.Text= "" Then
err.SetError(TextBox2, "Error2'.")
End If

' Here I need to check if the err (ErrorProvider) has any
' errors. I need some kinda function like err.HasErrors, so I
' can exit the sub now if errors occurs.

..
..
Call SaveMyData
End Sub

Is there a way to test the ErrorProvider to see if it has erros?

Thanks!

M O J O

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Herfried K. Wagner [MVP] (VIP)
* M O J O <Click here to reveal e-mail address> scripsit:
> How do I check if an ErrorProvider has errors?

Untested:

\\\
If ErrorProvider1.GetError(Me.TextBox1).Length > 0 Then
...
End If
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
M O J O
Hi Herfried,

Thanks for answering my post.

Please see my response to Peter.

M O J O

Herfried K. Wagner [MVP] wrote:

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Peter Huang (VIP)
Hi Mojo,

Thanks for using Microsoft MSDN Managed Newsgroup. My name is Peter, and I
will be assisting you on this issue.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to trap if an
ErrorProvider has errors.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I agree with Herfried's suggestion. I also has made a test.
Dim err As System.Windows.Forms.ErrorProvider
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Me.TextBox1.Text = "" Then
err.SetError(Me.TextBox1, "Error1")
Else
' Clear the error, if any, in the error provider.
err.SetError(Me.TextBox1, "")
End If
If Me.TextBox2.Text = "" Then
err.SetError(Me.TextBox2, "Error2")
Else
' Clear the error, if any, in the error provider.
err.SetError(Me.TextBox2, "")
End If
If err.GetError(Me.TextBox1).Length > 0 Or
err.GetError(Me.TextBox2).Length > 0 Then
MsgBox("HAS ERROR")
End If
End Sub

Private Sub Form2_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
err = New System.Windows.Forms.ErrorProvider
End Sub

Please Apply My Suggestion Above And Let Me Know If It Helps Resolve Your
Problem.

Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
M O J O
Hi Peter,

Well if I have 30 controls on my form, then the ....

If err.GetError(Me.TextBox1).Length > 0 Or _
err.GetError(Me.TextBox2).Length > 0 Or _
err.GetError(Me.TextBox3).Length > 0 Or _
err.GetError(Me.TextBox4).Length > 0 Or _
..
..
err.GetError(Me.TextBox30).Length > 0 Or Then

MsgBox("HAS ERROR")

End If

..... line will be rather long.

Then iw tould be easier with something like...

If err.HasErrors Then
MsgBox("HAS ERROR")
End If

I can derive the class an make my own ErrorProvider, but I was hoping
this "simple" HasError command were build into the ErrorProvider.

Thanks,

M O J O

Peter Huang wrote:
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Armin Zingler
"M O J O" <Click here to reveal e-mail address> schrieb
[Original message clipped]

Why not put the textboxes in an array once, later use a loop?

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
M O J O
Hi Armin,

Well I created my own ErrorProider like this....

Public Class MojoErrorProvider
Inherits System.Windows.Forms.ErrorProvider

#Region " Component Designer generated code "

Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub

Public Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container
End Sub

#End Region

Private _errorList As New ArrayList
Private _activeControl As Control

Public Shadows Sub SetError(ByVal control As Control, ByVal value
As String)
If value = "" Then
If _errorList.Contains(control) Then
_errorList.Remove(control)
End If
Else
If Not _errorList.Contains(_errorList) Then
_errorList.Add(control)
End If
End If
MyBase.SetError(control, value)
End Sub

Public Shadows Sub SetError(ByVal value As String)
If _activeControl Is Nothing Then
Throw New Exception("Active control has not been set.")
End If

Call Me.SetError(_activeControl, value)
End Sub

Public Sub ClearError(ByVal control As Control)
If _errorList.Contains(control) Then
_errorList.Remove(control)
End If

MyBase.SetError(control, "")
End Sub

Public Sub ClearError()
If _activeControl Is Nothing Then
Throw New Exception("Active control has not been set.")
End If

Call Me.ClearError(_activeControl)
End Sub

Public Sub ClearAll()
For Each control As control In _errorList
MyBase.SetError(control, "")
Next
_errorList.Clear()
End Sub

Public Function HasErrors() As Boolean
Return _errorList.Count > 0
End Function

End Class

So now I have the functionality I wanted.

:o)

Thanks for helping me out!

M O J O

Armin Zingler wrote:
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
Peter Huang (VIP)
Hi Mojo,

I am glad you find the solution to achieve your aim.

If you have any concern on this issue,please post here.

Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Collections.ArrayList
System.ComponentModel.Container
System.ComponentModel.IContainer
System.EventArgs
System.Object
System.Windows.Forms.ErrorProvider




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734