473,394 Members | 1,935 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,394 software developers and data experts.

Looping through controls....

I need to loop through a bunch of textbox controls on my form. The
order of the loop is very important. For example, the top one must be
read first, then the one below it, etc.

My first attempt was to put the controls in a Panel, and then loop
through the controls collection of the panel. What happened is it read
the controls from the bottom of my form to the top!

So I tried a more manual process. I named each textbox like this:

Textbox_1
Textbox_2
Textbox_3

Then tried a loop unsuccessfully:

For i as integer = 0 to 10
If Textbox_ & i.Text <> "" Then
'do something
End If
Next

This isn't exactly what i'm doing, but the idea is the same. Textbox_ &
i is causing an error because vb is reading it as a string. I need it
to be a control.

I know i'm missing something very obvious, but I just can't figure this
out!

Any ideas?
Thanks for all your help!

John

Nov 21 '05 #1
5 3962
"johnb41" <or****@informatik.com> schrieb:
I need to loop through a bunch of textbox controls on my form.


Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2
Hi John,

I'd suggest an automatic approach, not a manual approach: Iterate all then
controls putting them into an array, and sort the array with the Sort method
passing a custom IComparer class that you provide. In this comparer you take
2 controls and return the comparison, based on their Top/Left properties.
After the array is sorted, you iterate them again.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"johnb41" <or****@informatik.com> escribió en el mensaje
news:11*********************@f14g2000cwb.googlegro ups.com...
I need to loop through a bunch of textbox controls on my form. The
order of the loop is very important. For example, the top one must be
read first, then the one below it, etc.

My first attempt was to put the controls in a Panel, and then loop
through the controls collection of the panel. What happened is it read
the controls from the bottom of my form to the top!

So I tried a more manual process. I named each textbox like this:

Textbox_1
Textbox_2
Textbox_3

Then tried a loop unsuccessfully:

For i as integer = 0 to 10
If Textbox_ & i.Text <> "" Then
'do something
End If
Next

This isn't exactly what i'm doing, but the idea is the same. Textbox_ &
i is causing an error because vb is reading it as a string. I need it
to be a control.

I know i'm missing something very obvious, but I just can't figure this
out!

Any ideas?
Thanks for all your help!

John

Nov 21 '05 #3
John
I need to loop through a bunch of textbox controls on my form. The
order of the loop is very important. For example, the top one must be
read first, then the one below it, etc.

You make me curious about the text above. What is the reason for that.
They are not visible.

On the other hand have I the idea that looping though them will cost you
more code than access them individualy.

You can put them all in an array and than access them looping through that
Dim mycontrolArray() as control = {myTextBox1,MyButton2 etc}

for each ctr in myControlArray
ctr.Text = "whatever"
next

However probably as I said more work than access them individually.

I hope this helps,

Cor
Cor
Nov 21 '05 #4
Cor,

Your solutions seems to make the most sense for my project. I'll try
it out, thanks!

John

Nov 21 '05 #5
Dear Herfried K. Wagner,
The code in the link you specified has a bug in it. What happened if the
specified named control is not found! It will return a null vlaue so each
you should check for null :-)

Regards,
Ashok

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eU**************@TK2MSFTNGP15.phx.gbl...
| "johnb41" <or****@informatik.com> schrieb:
| >I need to loop through a bunch of textbox controls on my form.
|
| Accessing controls by their names or indices
| <URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #6

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

Similar topics

2
by: Ivo | last post by:
Hi, I have an audio file (.mid or .wav or .mp3) in an object element: <object id="snd" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"...
1
by: Jozef | last post by:
Hello, I'm trying to loop through forms by doing a "For Each" in the Currentdb. I'm doing this like the following; Dim db as dao.database Dim docLoop as document Dim ctrl as control Set db...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
2
by: Shawn | last post by:
Hi. I'm trying to loop through all webcontrols in my System.Web.UI.HtmlControls.HtmlForm. This is my code: Dim form As HtmlForm Dim control As Control form = Me.FindControl("completion")...
5
by: Craig G | last post by:
how do i go about this thru serverside code (VB.NET)? any links to any articles anywhere? basically i just want something simple that will loop thru all txt & cbo server side controls, and then...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
6
by: jobs | last post by:
This code was working, but then stopped working. I don't think I completely understand it. I pass it a formview name and it would loop through checking the value of textboxes. problem is...
0
by: Rene Goris | last post by:
Hi all, I am trying to add meta:resourcekey's to database programmatically looping throug webcontrols, but i cann't read the 'meta:resourcekey' from the webcontrol. The 'meta:resourcekey' will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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:
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
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...

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.