473,887 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4011
"johnb41" <or****@informa tik.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=controlbyna meindex&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****@informa tik.com> escribió en el mensaje
news:11******** *************@f 14g2000cwb.goog legroups.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,MyB utton2 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******** ******@TK2MSFTN GP15.phx.gbl...
| "johnb41" <or****@informa tik.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=controlbyna meindex&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
2581
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" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf. cab#Version=5,1,52,701" type="application/x-oleobject" width="282" height="53"> <param name="FileName" value="Tjaikovsky_-_The_sorcerers_apprentice.mid" /> <param name="loop" value="true" /> <... more presentational params...
1
6448
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 = CurrentDb
16
7248
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
4236
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") For Each control In form.Controls ....
5
1747
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 set there back color dependant on whether they are enabled or not Cheers, Craig
7
5478
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 loop through the filtered GridView to identify the selected rows and assemble some XML to be sent to a stored proc. The problem I have is that when looping through the GridView, it doesn't
6
6115
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 now as i debug it, it's telling me there are only a count of 3 controls in that for loop. and they have clientid values like: ctl00_Content1_FormMaint_ctl03
0
2901
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 not show up as attribute. How can i get the value of the 'meta:resourcekey' ? THE CODE: public string RetrieveControls(Control myControl){
0
11173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10877
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9593
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7143
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5810
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4633
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4239
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.