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

Dynamic control names

I have a form that has 156 list boxes on it. Is there a way to refer to each on in a for loop to populate their data instead of writing code for each one

for example

for(int x;x < 156;x++
listBox x = somethin

instead of
listBox1 = somethin
listBox2 = somethin
...
listBox156 = something
Nov 15 '05 #1
3 1186
=?Utf-8?B?RXJpYw==?= <an*******@discussions.microsoft.com> wrote:
I have a form that has 156 list boxes on it. Is there a way to refer to each
on in a for loop to populate their data instead of writing code for each one?

for example:

for(int x;x < 156;x++)
listBox x = something

instead of
listBox1 = something
listBox2 = something
...
listBox156 = something


Yes - use an array (or ArrayList) instead to start with. It's not as
"designer-friendly" but *much* more maintenance-friendly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Hi eric,

You can keep them referenced on a ArrayList the thing is how to know what
to place on each one, you have to think about it,
if you want to use the designer and still be able to treat them as a whole
you could iterate in the Controls collection after the controls are created
and if the control is a ListBox add it to the ArrayList.

One advice, the loading of this form can be very slow, as the designer code
may not be the best way for doing so. if you do not need keep an individual
reference I would recommend you to change the code of the designer, once you
finish designing it.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Eric" <an*******@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com...
I have a form that has 156 list boxes on it. Is there a way to refer to each on in a for loop to populate their data instead of writing code for
each one?
for example:

for(int x;x < 156;x++)
listBox x = something

instead of
listBox1 = something
listBox2 = something
...
listBox156 = something

Nov 15 '05 #3
Eric wrote:
I have a form that has 156 list boxes on it. Is there a way to refer
to each on in a for loop to populate their data instead of writing
code for each one?


You could loop through the control array on the form, picking out the
listboxes.
--
Mike Swaim sw***@hal-pc.org at home
mp*****@mdanderson.org or ms****@odin.mdacc.tmc.edu at work
Disclaimer: Yeah, like I speak for MD Anderson.
Quote: "Boingie"^4 Y,W & D
Nov 15 '05 #4

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

Similar topics

1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Teros | last post by:
Ello... What I'm trying to do is have a page layout with x columns by 4 rows. The first row would be names pulled from a dataset. The second row would be checkboxes - each being its own...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
4
by: Bhavin | last post by:
How can I capture user entered values from dynamically created controls in ASP.NET ? Thanks,
4
by: Paul W | last post by:
i have some dynamic controls that i add to a webform (actually, i dynamiclly build a table and add the controls to cells). some of these controls are HtmlSelect controls with the multiple property...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
7
by: marfi95 | last post by:
Hi all, I have an app that contains a tab control with a tabpage on it. As part of the interface, the user keys in a field that basically identifies how many instances of these tabpages to...
9
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user...
1
by: Roxxe | last post by:
i've got a website using masterpages, on a certain page i'm using dynamic added controls with specific names like "q1, q2, ...", but when i look in the sourcecode of the website it makes it like :...
26
by: Aaron \Castironpi\ Brady | last post by:
Hello all, To me, this is a somewhat unintuitive behavior. I want to discuss the parts of it I don't understand. .... f= lambda: n .... 9 9
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.