Click here to Skip to main content
15,921,463 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi friends,
Please tell How to create a Controls using Array list in C#.Net ?and how to handle them?Please Help me...
Posted
Comments
[no name] 8-Nov-11 8:25am    
Your question makes no sense. Please clarify
Abhinav S 8-Nov-11 8:33am    
You should not really be using control arrays in .Net unless there is some specific need.
The Control array concept disappeared once the .Net framework arrived.

the ArrayList is not type safe. you can use generic list like

C#
List<Button> lstButtons = new List<Button>();
 
Share this answer
 
v2
Comments
BobJanova 8-Nov-11 10:50am    
I edited your solution to fix the HTML (generics tend to fight with it).
An Arraylist is only a collection of objects.
It is not a Control.

You can store anything you want in a arraylist

C#
var arrayList1 = new ArrayList();
arrayList1.Add("a string"); // a string
arrayList1.Add(2); // a number
arrayList1.Add(new Object()); // an object

You can also add controls

C#
arrayList1.Add(new Button());
arrayList1.Add(new Textbox());



This won't show your objects, you only use the Arraylist to store them for later use in a convenient way.
 
Share this answer
 
Comments
naraayanan 8-Nov-11 9:22am    
Hi friends ,
Thanks for you reply.
Just create an ArrayList and the add controls to it.

C#
ArrayList<control> controls = new ArrayList<control>();

controls.Add(new TextBox());
controls.Add(new ListBox());
controls.Add(new Label());
 
Share this answer
 
v2
Comments
BobJanova 8-Nov-11 10:49am    
Don't you mean List<Control>?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900