473,890 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles btnOK.Click
If TextBox1.Text = "" Then
ErrorProvider1. SetError(TextBo x1, "Error")
ErrorCounter += 1
Else
ErrorProvider1. SetError(TextBo x1, "")
End If

If TextBox2.Text = "" Then
ErrorProvider1. SetError(TextBo x2, "Error2")
ErrorCounter += 1
Else
ErrorProvider1. SetError(TextBo x2, "")
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 9864
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(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles btnOK.Click
If TextBox1.Text = "" Then
ErrorProvider1. SetError(TextBo x1, "Error")
ErrorCounter += 1
Else
ErrorProvider1. SetError(TextBo x1, "")
End If

If TextBox2.Text = "" Then
ErrorProvider1. SetError(TextBo x2, "Error2")
ErrorCounter += 1
Else
ErrorProvider1. SetError(TextBo x2, "")
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(ErrorProvid er1.GetError(ct rl)) > 0 Then
strErrorList += ErrorProvider1. GetError(ctrl) & ChrW(10) &
ChrW(13)
End If
Next

If Len(strErrorLis t) = 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****@informa tik.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(ByV al sender As System.Object, ByVal e As
System.EventAr gs) Handles btnOK.Click
If TextBox1.Text = "" Then
ErrorProvider1. SetError(TextBo x1, "Error")
ErrorCounter += 1
Else
ErrorProvider1. SetError(TextBo x1, "")
End If

If TextBox2.Text = "" Then
ErrorProvider1. SetError(TextBo x2, "Error2")
ErrorCounter += 1
Else
ErrorProvider1. SetError(TextBo x2, "")
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 ErrorProviderEr rorsList(ByVal provider As
ErrorProvider) As String()
Dim errors As New ArrayList
ErrorProviderEr rorsList(provid er,
provider.Contai nerControl.Cont rols, errors)
Return DirectCast(erro rs.ToArray(GetT ype(String)), String())
End Function

Private Shared Sub ErrorProviderEr rorsList(ByVal provider As
ErrorProvider, ByVal controls As Control.Control Collection, ByVal
errors As ArrayList)
Dim s As String
For Each ctl As Control In controls
s = provider.GetErr or(ctl)
If s.Length > 0 Then
errors.Add(s)
End If

ErrorProviderEr rorsList(provid er, 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(ErrorProvid er1.GetError(ct rl)) > 0 Then
strErrorList += ErrorProvider1. GetError(ctrl) & ChrW(10) &
ChrW(13)
End If
Next

If Len(strErrorLis t) = 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****@newsgro up.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 ErrorProviderEr rorsList(ByVal provider As
ErrorProvide r) As String()
Dim errors As New ArrayList
ErrorProviderEr rorsList(provid er,
provider.Conta inerControl.Con trols, errors)
Return DirectCast(erro rs.ToArray(GetT ype(String)), String())
End Function

Private Shared Sub ErrorProviderEr rorsList(ByVal provider As
ErrorProvide r, ByVal controls As Control.Control Collection, ByVal
errors As ArrayList)
Dim s As String
For Each ctl As Control In controls
s = provider.GetErr or(ctl)
If s.Length > 0 Then
errors.Add(s)
End If

ErrorProviderEr rorsList(provid er, 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

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

If Len(strErrorLis t) = 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
5547
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. After the data is corrected, the hint does not disappear ! (the exclamation mark however, does disappear). For Microsoft: If I'm correct, and it is a bug, can it be corrected ?
6
9863
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
2627
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, basically I want the ErrorProvider to automatically pick up database errors, but have so far had no...
2
6965
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 : Build a dataset containing a single table. Bind the textboxes on a windows form to the datatable. Bind the errorprovider control to the same datatable. Use SetColumnError to create an error condition in the datatable.
4
3823
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 to make it so that the ErrorProvider message is always displayed when the mouse is over the...
5
1672
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 for the first time it fails and the errorprovider shows an error icon, something that I obviously...
1
1068
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 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
0
265
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 like, but just in grids. Is there any way to remove the column name and colon from the tooltips?
4
1480
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
0
9819
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11222
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10810
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10460
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9625
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8015
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5845
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4674
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4270
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.