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