473,545 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using ErrorProvider

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(Te xtBox1, "Error1'.")
End If

If TextBox2.Text= "" Then
err.SetError(Te xtBox2, "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

Nov 20 '05 #1
6 9845
* M O J O <mojo@_no_spam_ delete_this_new websolutions.dk > scripsit:
How do I check if an ErrorProvider has errors?


Untested:

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

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
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.ErrorProv ider
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
If Me.TextBox1.Tex t = "" 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.Tex t = "" 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).Leng th > 0 Or
err.GetError(Me .TextBox2).Leng th > 0 Then
MsgBox("HAS ERROR")
End If
End Sub

Private Sub Form2_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
err = New System.Windows. Forms.ErrorProv ider
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.

Nov 20 '05 #3
Hi Peter,

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

If err.GetError(Me .TextBox1).Leng th > 0 Or _
err.GetError(Me .TextBox2).Leng th > 0 Or _
err.GetError(Me .TextBox3).Leng th > 0 Or _
err.GetError(Me .TextBox4).Leng th > 0 Or _
..
..
err.GetError(Me .TextBox30).Len gth > 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:
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.ErrorProv ider
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
If Me.TextBox1.Tex t = "" 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.Tex t = "" 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).Leng th > 0 Or
err.GetError(Me .TextBox2).Leng th > 0 Then
MsgBox("HAS ERROR")
End If
End Sub

Private Sub Form2_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
err = New System.Windows. Forms.ErrorProv ider
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.


Nov 20 '05 #4
Hi Herfried,

Thanks for answering my post.

Please see my response to Peter.

M O J O

Herfried K. Wagner [MVP] wrote:
* M O J O <mojo@_no_spam_ delete_this_new websolutions.dk > scripsit:
How do I check if an ErrorProvider has errors?

Untested:

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


Nov 20 '05 #5
"M O J O" <mojo@_no_spam_ delete_this_new websolutions.dk > schrieb
Well if I have 30 controls on my form, then the ....

If err.GetError(Me .TextBox1).Leng th > 0 Or _
err.GetError(Me .TextBox2).Leng th > 0 Or _
err.GetError(Me .TextBox3).Leng th > 0 Or _
err.GetError(Me .TextBox4).Leng th > 0 Or _
..
..
err.GetError(Me .TextBox30).Len gth > 0 Or Then

MsgBox("HAS ERROR")

End If


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

Nov 20 '05 #6
Hi Armin,

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

Public Class MojoErrorProvid er
Inherits System.Windows. Forms.ErrorProv ider

#Region " Component Designer generated code "

Public Sub New(ByVal Container As System.Componen tModel.IContain er)
MyClass.New()

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

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeCompo nent() 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.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Component Designer
Private components As System.Componen tModel.IContain er

'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.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r
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.Cont ains(control) Then
_errorList.Remo ve(control)
End If
Else
If Not _errorList.Cont ains(_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("Acti ve control has not been set.")
End If

Call Me.SetError(_ac tiveControl, value)
End Sub
Public Sub ClearError(ByVa l control As Control)
If _errorList.Cont ains(control) Then
_errorList.Remo ve(control)
End If

MyBase.SetError (control, "")
End Sub
Public Sub ClearError()
If _activeControl Is Nothing Then
Throw New Exception("Acti ve 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.Clea r()
End Sub
Public Function HasErrors() As Boolean
Return _errorList.Coun t > 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:
"M O J O" <mojo@_no_spam_ delete_this_new websolutions.dk > schrieb
Well if I have 30 controls on my form, then the ....

If err.GetError(Me .TextBox1).Leng th > 0 Or _
err.GetError(Me .TextBox2).Leng th > 0 Or _
err.GetError(Me .TextBox3).Leng th > 0 Or _
err.GetError(Me .TextBox4).Leng th > 0 Or _
..
..
err.GetError(Me .TextBox30).Len gth > 0 Or Then

MsgBox("HAS ERROR")

End If

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


Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3141
by: Dan K. | last post by:
Hi NG, the problem : im working with the error provider (EP) to remind users of filling required fields. in each control i ve a check method which check the field inputs and set if needed the error provider. also in each control one method to reset all error providers ... looks like this : /// <summary>Clears all ErrorProvider</summary>
1
3052
by: OShell77 | last post by:
Hi, I have problem with a C# Win Forms app that uses the ErrorProvider class to provide input validation feedback to the user. On my development workstation (WinXP Pro + Visual Studio .NET 2003), when I run the app by itself or from VS in debug, everything works fine... the ErrorProvider tooltips display correctly, etc. However, on other...
0
1321
by: Issac | last post by:
Hi, I am writing a program which will be used in Win2000 and Win98 platform. The program include a Form (called myForm) which has a TextBox, Tooltip, Errorprovider and a Button. Tooltip will be set with TextBox content and Errorprovider will be set in TextBox Validating event if it is empty. The Button is actually pop (ShowDialog)...
3
2611
by: Jeppe Jespersen | last post by:
I read the following - regarding the ErrorProvider control - in the MOC Course Material for course 2373: "You can set your own error messages manually, as shown in the following example, or when working with bound data, you set the DataSource propertyof the ErrorProvider to automatically pick error messages up from thedatabase." So,...
4
3800
by: ljlevend | last post by:
I have the following issues: 1. I want to make it so that ToolTips never go away once they are shown until the user moves the mouse outside of the control for which the ToolTip is assigned. It seems to me that setting the ToolTip.AutoPopDelay to a large value (e.g., Int32.MaxValue) should acomplish this goal, but it does not. 2. I want...
5
1654
by: Alvaro Lamas | last post by:
I have a problem with the ErrorProvider with a mdi interface, I have a MDI form which opens a child form, that child form uses the errorprovider to show the problems with the data entry. The problem happens when I use the show method of the child form it will try to validate the first field and since it need to not empty and its just opening...
5
3919
by: Ryan | last post by:
A binding navigator control adds the following code for when the Save button is clicked: Me.Validate() Me.UserBindingSource.EndEdit() Me.UserTableAdapter.Update(Me.UserDataSet.User)" You can add code to the column changing event for the dataset by using the dataset designer, for example: Private Sub UserDataTable_ColumnChanging(ByVal...
4
1458
by: Freeon | last post by:
How do I capture the hover event on the ErrorProvider control? I created a custom control and inherited the ErrorProvider. Problem is I don't know which method to override to capture the hover event. I want to popup a custom form instead of the default tooltip. Any help would be greatly appreciated. Thanks, Christian
2
2285
by: buddyr | last post by:
Hello, I have form in C#. I want to use the errorprovider control to prompt user for data if nothing is entered. example: I have textbox1 for user to enter name. I have radiobuttons for job departments. I click a button and data displays in labels. label1.text = textbox1; if (radiobutton1.clicked)
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7808
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7423
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.