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

programmatically created droplistboxes

I need to name the controls uniquely so I can load/access their items.
Ie: a listbox control.
I need to create a variable number of controls.
I tried to name them like this:
DropListControl ddlControl+ctr = new DropListControl();

This doesn't work.

Can anyone offer suggestions?
Thanks
Nov 17 '05 #1
4 1235
MotorcycleIke wrote:
I need to name the controls uniquely so I can load/access their items.
Ie: a listbox control.
I need to create a variable number of controls.
I tried to name them like this:
DropListControl ddlControl+ctr = new DropListControl();


One way to go would be to use an array of controls, like this:

int numControls = 20;
DropListControl[] controls = new DropListControl[numControls];
for (int i = 0; i < numControls; i++)
controls[i] = new DropListControl();

Note that you have to create each actual control in turn, the initial
"new" will only create the array itself.

Of course, if you have no idea how many of the controls you are going to
need, it might be better to use a collection type instead of an array. In
that case, you might want to use an ArrayList instead or create your own
typed collection, just like you would for any other data type.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #2
MotorcycleIke wrote:
I need to name the controls uniquely so I can load/access their items.
Ie: a listbox control.
I need to create a variable number of controls.
I tried to name them like this:
DropListControl ddlControl+ctr = new DropListControl();


One way to go would be to use an array of controls, like this:

int numControls = 20;
DropListControl[] controls = new DropListControl[numControls];
for (int i = 0; i < numControls; i++)
controls[i] = new DropListControl();

Note that you have to create each actual control in turn, the initial
"new" will only create the array itself.

Of course, if you have no idea how many of the controls you are going to
need, it might be better to use a collection type instead of an array. In
that case, you might want to use an ArrayList instead or create your own
typed collection, just like you would for any other data type.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #3
Hi,

No, it;s not possible, you can keep a reference in an ArrayList for example

why you need it for? most of the time you do not need to keep a reference to
a control , you just hook the events you need and handle them, probably with
the same method.

You could use the ID property to later identify it.

Also remember to include them in the Controls collection

Also remember to recreate them when the page is submited back.
cheers,

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

"MotorcycleIke" <no***********@yahoo.com> wrote in message
news:VK********************@comcast.com...
I need to name the controls uniquely so I can load/access their items.
Ie: a listbox control.
I need to create a variable number of controls.
I tried to name them like this:
DropListControl ddlControl+ctr = new DropListControl();

This doesn't work.

Can anyone offer suggestions?
Thanks

Nov 17 '05 #4
Hi,

No, it;s not possible, you can keep a reference in an ArrayList for example

why you need it for? most of the time you do not need to keep a reference to
a control , you just hook the events you need and handle them, probably with
the same method.

You could use the ID property to later identify it.

Also remember to include them in the Controls collection

Also remember to recreate them when the page is submited back.
cheers,

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

"MotorcycleIke" <no***********@yahoo.com> wrote in message
news:VK********************@comcast.com...
I need to name the controls uniquely so I can load/access their items.
Ie: a listbox control.
I need to create a variable number of controls.
I tried to name them like this:
DropListControl ddlControl+ctr = new DropListControl();

This doesn't work.

Can anyone offer suggestions?
Thanks

Nov 17 '05 #5

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

Similar topics

3
by: R Reyes | last post by:
Just wondering if anyone knows the pros/cons between creating a database programmatically vs using the application's tool windows/features that come with SQLServer, Access, Oracle, etc... Is it...
1
by: John Criswell | last post by:
I have created a radio button list programmatically. C# SqlConnection conn = new SqlConnection("data source=localhost; integrated security=true; initial catalog=pubs"); SqlCommand cmdAuthors =...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
0
by: TB | last post by:
Hi All: I have this page where a rows / cells are programmatically added to to table by pushing a button. The rows contain a textbox and a associated button. What I want to is to be able to...
0
by: John Smith | last post by:
How do I retrieve the ServiceName of the service I am currently running programmatically? I have a class that I have created that I want to programmatically get the name of my current service. ...
4
by: Bob | last post by:
Hi, I'm working with VWD and i defined programmatically a button (in code-behind) with an ID. So I expect to see beside "Page Events" and "Form1" my button "b1" in order to use the Click event....
2
by: OceanBreeze | last post by:
Border drawn in C# Table programmatically even if several adjacent horizontal & vertical cells are empty in the table I want to programmatically have border on each and every row and column in the...
8
by: hunanwarrior | last post by:
I added textbox controls to a form when user selects amount to create from a combobox as follows: 'Load up the combobox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As...
0
by: =?Utf-8?B?S29uc3RhbnRpbg==?= | last post by:
I am currently working on the application that need to simulate basic authentication programmatically using user's credentials that are known. Basically, the need is for a single sign on with a...
4
by: Siv | last post by:
Hi, I have an application that reads information from a database and depending on that information creates controls on a form. Depending on where the user is at in a process there may be one item...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.