all groups > vb.net > april 2005 >
You're in the

vb.net

group:

Is there any way to for/each controls?


Is there any way to for/each controls? Terry Olsen
4/29/2005 10:31:15 PM
vb.net:
Is there any way to run through all controls on a form using a For Each
loop? Say I want to clear all textboxes on a form...what's the best way to
do that?

Re: Is there any way to for/each controls? Cor Ligthert
4/30/2005 12:00:00 AM
Terry,

There is no best way.
My sample is this one.
\\\
doset(Me)
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
'DoSomething
doSet(ctr)
Next
End Sub
///
I take the start others take the child.

Be aware that you cannot use this to delete controls.
Than you can beter use a Z order loop.

I hope this helps,

Cor

Re: Is there any way to for/each controls? Herfried K. Wagner [MVP]
4/30/2005 12:00:00 AM
"Terry Olsen" <tolsen64@hotmail.com> schrieb:
[quoted text, click to view]

<URL:http://dotnet.mvps.org/dotnet/samples/controls/EnumerateControls.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Re: Is there any way to for/each controls? Stuart Nathan
4/30/2005 12:00:00 AM
dim ctl as Control
for each ctl in Me.Controls
ctl.dispose()
next

Re: Is there any way to for/each controls? Supra
5/2/2005 12:00:00 AM
Public Sub ClearAllChildFormText()
' Obtain a reference to the currently active MDI child form.
Dim tempChild As Form = Me.ActiveMdiChild

' Loop through all controls on the child form.
Dim i As Integer
For i = 0 To tempChild.Controls.Count - 1
' Determine if the current control on the child form is a TextBox.
If TypeOf tempChild.Controls(i) Is TextBox Then
' Clear the contents of the control since it is a TextBox.
tempChild.Controls(i).Text = ""
End If
Next i
End Sub 'ClearAllChildFormText



[quoted text, click to view]
AddThis Social Bookmark Button