473,248 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,248 software developers and data experts.

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(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

Nov 20 '05 #1
6 9831
* M O J O <mojo@_no_spam_delete_this_newwebsolutions.dk> 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>
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.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.

Nov 20 '05 #3
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:
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.


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_newwebsolutions.dk> scripsit:
How do I check if an ErrorProvider has errors?

Untested:

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


Nov 20 '05 #5
"M O J O" <mojo@_no_spam_delete_this_newwebsolutions.dk> schrieb
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


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 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:
"M O J O" <mojo@_no_spam_delete_this_newwebsolutions.dk> schrieb
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

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
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...
1
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...
0
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...
3
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...
4
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...
5
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...
5
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...
4
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...
2
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...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.