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

Is there any way to for/each controls?

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?
Nov 21 '05 #1
4 953
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
Nov 21 '05 #2
"Terry Olsen" <to******@hotmail.com> schrieb:
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?


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

Nov 21 '05 #3
dim ctl as Control
for each ctl in Me.Controls
ctl.dispose()
next
Nov 21 '05 #4
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

Terry Olsen wrote:
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?

Nov 21 '05 #5

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

Similar topics

6
by: Kiteman - Canada | last post by:
I have the following: a form called Form1 an image called Image1 twelve lines that have been drawn and superimposed on the image I wish to have a command button that will toggle the lines on...
80
by: | last post by:
Is there a performance difference between this: \\\ Dim i As Integer For i = 0 to myObject.Controls.Count - 1 myObject.Controls(i) = ... Next /// and this:
2
by: crjunk | last post by:
I'm trying to write a piece of code that will programatically save a record automatically without me having to add a new ' Row.Item("ADD1") = txtAdd1.Text.Trim.ToUpper ' type command each time I...
2
by: Dexter | last post by:
Hello all, I have webform1, and i need to make a bow to catch all textbox in my webform1. I tray this, but don't function. Dim obj As System.Web.UI.WebControls.TextBox Dim cont As Integer For...
112
by: Tom | last post by:
This is very strange: I have a Windows Form with a Panel on it. In that panel I dynamically (at run time) create some labels, as so: for i=1 to x dim ctlNew as New Label() with ctlNew...
7
by: Tangent | last post by:
I know this was asked before, but I never saw what the answer was... I have a webform (asp.net) that has a number of dropdownlists (and other controls). I am trying to use a For Each...Next loop...
18
by: Martin Williams | last post by:
I have a working version of my survey program, but i'm trying to optimize now. On the last page, i have a sub that examines all of the answers and assigns them to variables for uploading to the...
4
by: Toze | last post by:
I'm using a assembly to load my apllication (ex: Mobi.exe), and now I need to list all forms in my apllication and list all controls (ex: txtname;btnname) inside of each form.
0
by: KR | last post by:
I finally got back to this. The syntax that worked for me was: For Each ctlarray As Control.ControlCollection _ In New Control.ControlCollection() _ { Form1.Controls _ ,...
3
by: Eps | last post by:
Hi, I am writing an mp3 player using wpf, I have three user controls (media library, media controls and a playlist). Obviously I need these to interact with each other, I assume the best way to...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
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,...
0
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...

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.