K
koffietje
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?
are empty are not by using a for each... in .. structure
in VB.Net?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?
* "Ken Tucker said:If TypeOf (ctrl) Is TextBox Then
* "koffietje said:How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?
koffietje said:How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?
-----Original Message-----
Hi,
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf (ctrl) Is TextBox Then
Dim tb As TextBox = ctrl
If tb.Text = "" Then
tb.Text = "Empty"
End If
End If
Next
Ken
---------------------------------------
.
-----Original Message-----
Hi Java,
When all textboxes are on the main form (windowform)
Rough written so don't look at typo's
\\\
dim ctr as control
for each ctr in me.controls
if typeof ctr is textbox then
if ctr.text <>"" then
'do something
end if
end if
next
///
If it is a webform "text" is not in the control and you have to cast it
first, but that is a problem itself, but I thought I have somewhere saved a
solution, so tell that than again.
I hope this helps a little bit,
Cor
.
-----Original Message-----
Hi Koffietje,
You need one of two methods depending on whether your TextBoxes are
directly on the Form or whether some are held within other Controls such as
Panels.
If all the TextBoxes are directly on the Form then the methods shown by
Cor and Ken will be fine.
If there are any TextBoxes inside other Controls then a recursive method
is required: An example is shown below. Form is a Control so it starts off
with the Form passing itself (Me).
In the Form:
CheckTheTextBoxes (Me)
Sub CheckTheTextBoxes (oControl As Control)
Dim oChildControl As Control
For Each oChildControl in oControl.Controls
If TypeOf (oChildControl) Is TextBox _
AndAlso oChildControl.Text = "" Then 'or
-----Original Message-----
* "koffietje" <[email protected]> scripsit:
oads/EnumerateControls.zip>
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
.
* "koffietje said:Hi Ken, exactly what I was looking for! Thanks!
Notice that this code will not enumerate nested controls.
* "Cor said:But the answer from Fergus does and Java was answering that also
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.