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

Checking Controls for errors

I am using the following to see if an error exists on any of my controls on
my Windows Form (VS 2005)

' Check to see if errors exist
'
For Each ctrl As Control In Me.Controls
If ErrorProvider1.GetError(ctrl) <"" Then
invalidInput = True
End If
Next

I have three group controls on my form and in each group control, there are
4 textboxes. The above code checks the group control but bypasses the
textboxes.

How can I include the textboxes?

Thanks in advance

Feb 16 '07 #1
3 937

"Zim Babwe" <zi******@doyoureallythinkthisisreal.comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
>I am using the following to see if an error exists on any of my controls
on my Windows Form (VS 2005)

' Check to see if errors exist
'
For Each ctrl As Control In Me.Controls
If ErrorProvider1.GetError(ctrl) <"" Then
invalidInput = True
End If
Next

I have three group controls on my form and in each group control, there
are 4 textboxes. The above code checks the group control but bypasses
the textboxes.

How can I include the textboxes?

Thanks in advance
You can use a recursive routine to access all the controls. Your loop hits
the GroupControl and doesn't look *inside* it.

Or you can specifically check the textboxes inside the GroupControl.

Here's how you could do it recursively. I didn't test this, but it should
work (famous last words). Call it and pass it the form, like this:

CheckForErrors(myForm)
if invalidInput Then
...
End If

'This needs to be outside the routine.
Dim invalidInput As Boolean

Private Sub CheckForErrors(ByVal ctrlContainer As Control)
For Each ctrl As Control In ctrlContainer.Controls
If TypeOf ctrl Is TextBox _
AndAlso ErrorProvider1.GetError(ctrl) <String.Empty Then
invalidInput = True
Return
End If
'If control has children, call this function recursively
If ctrl.HasChildren Then
CheckForErrors(ctrl)
'If it found any invalid inputs in this container, return.
If invalidInput Then Return
End If
Next
End Sub

Good luck.
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
Feb 16 '07 #2
Thanks. This is just what I need.
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:pe******************************@comcast.com. ..
>
"Zim Babwe" <zi******@doyoureallythinkthisisreal.comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
>>I am using the following to see if an error exists on any of my controls
on my Windows Form (VS 2005)

' Check to see if errors exist
'
For Each ctrl As Control In Me.Controls
If ErrorProvider1.GetError(ctrl) <"" Then
invalidInput = True
End If
Next

I have three group controls on my form and in each group control, there
are 4 textboxes. The above code checks the group control but bypasses
the textboxes.

How can I include the textboxes?

Thanks in advance

You can use a recursive routine to access all the controls. Your loop hits
the GroupControl and doesn't look *inside* it.

Or you can specifically check the textboxes inside the GroupControl.

Here's how you could do it recursively. I didn't test this, but it should
work (famous last words). Call it and pass it the form, like this:

CheckForErrors(myForm)
if invalidInput Then
...
End If

'This needs to be outside the routine.
Dim invalidInput As Boolean

Private Sub CheckForErrors(ByVal ctrlContainer As Control)
For Each ctrl As Control In ctrlContainer.Controls
If TypeOf ctrl Is TextBox _
AndAlso ErrorProvider1.GetError(ctrl) <String.Empty Then
invalidInput = True
Return
End If
'If control has children, call this function recursively
If ctrl.HasChildren Then
CheckForErrors(ctrl)
'If it found any invalid inputs in this container, return.
If invalidInput Then Return
End If
Next
End Sub

Good luck.
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.


Feb 16 '07 #3
Cool. Glad I could help.
Robin S.
-----------------------------
"Zim Babwe" <zi******@doyoureallythinkthisisreal.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Thanks. This is just what I need.
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:pe******************************@comcast.com. ..
>>
"Zim Babwe" <zi******@doyoureallythinkthisisreal.comwrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
>>>I am using the following to see if an error exists on any of my controls
on my Windows Form (VS 2005)

' Check to see if errors exist
'
For Each ctrl As Control In Me.Controls
If ErrorProvider1.GetError(ctrl) <"" Then
invalidInput = True
End If
Next

I have three group controls on my form and in each group control, there
are 4 textboxes. The above code checks the group control but bypasses
the textboxes.

How can I include the textboxes?

Thanks in advance

You can use a recursive routine to access all the controls. Your loop
hits the GroupControl and doesn't look *inside* it.

Or you can specifically check the textboxes inside the GroupControl.

Here's how you could do it recursively. I didn't test this, but it
should work (famous last words). Call it and pass it the form, like
this:

CheckForErrors(myForm)
if invalidInput Then
...
End If

'This needs to be outside the routine.
Dim invalidInput As Boolean

Private Sub CheckForErrors(ByVal ctrlContainer As Control)
For Each ctrl As Control In ctrlContainer.Controls
If TypeOf ctrl Is TextBox _
AndAlso ErrorProvider1.GetError(ctrl) <String.Empty Then
invalidInput = True
Return
End If
'If control has children, call this function recursively
If ctrl.HasChildren Then
CheckForErrors(ctrl)
'If it found any invalid inputs in this container, return.
If invalidInput Then Return
End If
Next
End Sub

Good luck.
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.



Feb 17 '07 #4

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

Similar topics

23
by: sashan | last post by:
I'm a Python newbie. I have been using c++ for 5 years and before that I was programming in Pascal. The one thing that annoys me about python is dynamic typing because I find myself making...
6
by: Web Developer | last post by:
Hi, I come across the term "type checking" very often in my readings on C++, and have never heard it in Java. Besides the simplistic answer that it checks the "type", what more does it mean? ...
22
by: Qopit | last post by:
Hi there, I'm pretty new to Python and am trying to figure out how to get "will this code compile?"-like code checking. To me this is a pretty basic language/environment requirement, especially...
0
by: Mike Meyer | last post by:
The recent thread on threads caused me to reread the formal definition of SCOOP, and I noticed something I hadn't really impressed me the first time around: it's using staticly checkable rules to...
6
by: Neil | last post by:
Hi, I have an aspx page with a number of web controls on it and one of these is a cancel button. I want to check the page to see if the user has changed any of the controls, i..e typed some text...
10
by: Michael | last post by:
Hi Everyone. I have been designing a form with about 100 or so controls and today I pasted some code from another test project into this one and then all the controls on the form disapeared from...
9
by: D. Shane Fowlkes | last post by:
(ASP.NET 2 / VB) Question - How can I write a If statement to see if a control (textbox) actually exists on a page? Upon page_load, a certain control may or may not be visible on the page so I...
16
by: lawrence k | last post by:
I've made it habit to check all returns in my code, and usually, on most projects, I'll have an error function that reports error messages to some central location. I recently worked on a project...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
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...
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...

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.