473,406 Members | 2,439 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,406 software developers and data experts.

ErrorProvider... how to continue only when there are no errors

I have a form with a bunch of textboxes. Each text box gets validated
with the ErrorProvider. I want the form to process something ONLY when
all the textboxes are valid.

I found a solution, but it seems like a workaround. I'm not sure if
it's the best way:

Dim ErrorCounter As Integer

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "Error")
ErrorCounter += 1
Else
ErrorProvider1.SetError(TextBox1, "")
End If

If TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "Error2")
ErrorCounter += 1
Else
ErrorProvider1.SetError(TextBox2, "")
End If

If ErrorCounter = 0 Then
'process code that only happens when there are NO errors
End If
End Sub
Is this a good way to handle it, or am I missing a better technique?

Thanks!
John

Nov 21 '05 #1
4 9814
Hello John,
I have a form with a bunch of textboxes. Each text box gets validated
with the ErrorProvider. I want the form to process something ONLY when
all the textboxes are valid.

I found a solution, but it seems like a workaround. I'm not sure if
it's the best way:

Dim ErrorCounter As Integer

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "Error")
ErrorCounter += 1
Else
ErrorProvider1.SetError(TextBox1, "")
End If

If TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "Error2")
ErrorCounter += 1
Else
ErrorProvider1.SetError(TextBox2, "")
End If

If ErrorCounter = 0 Then
'process code that only happens when there are NO errors
End If
End Sub
Is this a good way to handle it, or am I missing a better technique?


I have no better idea _ seems this is OK.

If you are interested have a look at:
http://www.help-info.de/en/Visual_Ba...t.htm#download

HTH
Best regards
Ulrich Kulle
***************************************
http://www.help-info.de
***************************************
Nov 21 '05 #2
J L
You dont have to use a counter. You can step through the error
provider to see if any errors are set:

Dim ctrl As Control
Dim strErrorList As Stromg

strErrorList = ""
For Each ctrl In Me.Controls
If Len(ErrorProvider1.GetError(ctrl)) > 0 Then
strErrorList += ErrorProvider1.GetError(ctrl) & ChrW(10) &
ChrW(13)
End If
Next

If Len(strErrorList) = 0 Then
' Process stuff if no errors
Else
Messagebox.Show(strErrorList, "List Of Errors")
End If

John

On 4 Mar 2005 10:33:18 -0800, "johnb41" <or****@informatik.com> wrote:
I have a form with a bunch of textboxes. Each text box gets validated
with the ErrorProvider. I want the form to process something ONLY when
all the textboxes are valid.

I found a solution, but it seems like a workaround. I'm not sure if
it's the best way:

Dim ErrorCounter As Integer

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "Error")
ErrorCounter += 1
Else
ErrorProvider1.SetError(TextBox1, "")
End If

If TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "Error2")
ErrorCounter += 1
Else
ErrorProvider1.SetError(TextBox2, "")
End If

If ErrorCounter = 0 Then
'process code that only happens when there are NO errors
End If
End Sub
Is this a good way to handle it, or am I missing a better technique?

Thanks!
John


Nov 21 '05 #3

Also have to watch out if you're using a groupbox or other container
since those controls are not in Me.Controls but may be in the error
provider. I use a recursive routine to check..

Public Shared Function ErrorProviderErrorsList(ByVal provider As
ErrorProvider) As String()
Dim errors As New ArrayList
ErrorProviderErrorsList(provider,
provider.ContainerControl.Controls, errors)
Return DirectCast(errors.ToArray(GetType(String)), String())
End Function

Private Shared Sub ErrorProviderErrorsList(ByVal provider As
ErrorProvider, ByVal controls As Control.ControlCollection, ByVal
errors As ArrayList)
Dim s As String
For Each ctl As Control In controls
s = provider.GetError(ctl)
If s.Length > 0 Then
errors.Add(s)
End If

ErrorProviderErrorsList(provider, ctl.Controls, errors)
Next
End Sub
HTH,

Sam

On Sat, 05 Mar 2005 22:21:04 -0800, J L <jo**@marymonte.com> wrote:
You dont have to use a counter. You can step through the error
provider to see if any errors are set:

Dim ctrl As Control
Dim strErrorList As Stromg

strErrorList = ""
For Each ctrl In Me.Controls
If Len(ErrorProvider1.GetError(ctrl)) > 0 Then
strErrorList += ErrorProvider1.GetError(ctrl) & ChrW(10) &
ChrW(13)
End If
Next

If Len(strErrorList) = 0 Then
' Process stuff if no errors
Else
Messagebox.Show(strErrorList, "List Of Errors")
End If

John

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
Nov 21 '05 #4
J L
Very clever, Sam! Thanks.

On Mon, 07 Mar 2005 12:21:47 -0500, Samuel R. Neff
<bl****@newsgroup.nospam> wrote:

Also have to watch out if you're using a groupbox or other container
since those controls are not in Me.Controls but may be in the error
provider. I use a recursive routine to check..

Public Shared Function ErrorProviderErrorsList(ByVal provider As
ErrorProvider) As String()
Dim errors As New ArrayList
ErrorProviderErrorsList(provider,
provider.ContainerControl.Controls, errors)
Return DirectCast(errors.ToArray(GetType(String)), String())
End Function

Private Shared Sub ErrorProviderErrorsList(ByVal provider As
ErrorProvider, ByVal controls As Control.ControlCollection, ByVal
errors As ArrayList)
Dim s As String
For Each ctl As Control In controls
s = provider.GetError(ctl)
If s.Length > 0 Then
errors.Add(s)
End If

ErrorProviderErrorsList(provider, ctl.Controls, errors)
Next
End Sub
HTH,

Sam

On Sat, 05 Mar 2005 22:21:04 -0800, J L <jo**@marymonte.com> wrote:
You dont have to use a counter. You can step through the error
provider to see if any errors are set:

Dim ctrl As Control
Dim strErrorList As Stromg

strErrorList = ""
For Each ctrl In Me.Controls
If Len(ErrorProvider1.GetError(ctrl)) > 0 Then
strErrorList += ErrorProvider1.GetError(ctrl) & ChrW(10) &
ChrW(13)
End If
Next

If Len(strErrorList) = 0 Then
' Process stuff if no errors
Else
Messagebox.Show(strErrorList, "List Of Errors")
End If

John

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.


Nov 21 '05 #5

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

Similar topics

3
by: Martijn Leine | last post by:
I am using an errorprovider and a datagrid component on a form. I use the errorprovider to display error hints in the grid, in the case the entered data by the user is checked and not found Ok....
6
by: M O J O | last post by:
Hi, How do I check if an ErrorProvider has errors? Take for example this code... (err = ErrorProvider...) Public Sub Test If TextBox1.Text= "" Then
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...
2
by: Lenster | last post by:
I'm having problems using the errorprovider in VB.NET to automatically display an error icon next to textboxes bound to the same dataset as the errorprovider. The sequence of events is : ...
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...
1
by: johnb41 | last post by:
I have a form with a bunch of textboxes. Each text box gets validated with the ErrorProvider. I want the form to process something ONLY when ALL the textboxes are valid. I found a solution, but...
0
by: chris | last post by:
We are using the errorprovider to display errors in columns of a datatable. All works well, except that the tooltips display the errors in the format : for controls such as text boxes and the...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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,...

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.