Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possable to auto generate items on a form based on a list/database?
So for example a text box and two buttons for each item on a stock list, once the stock list has been created a button can be clicked which would generate a new form.
Posted

Yes, why not. Just in runtime add those controls in Controls collection like this :

Form f = new Form();
TextBox tb = new TextBox();
tb.Losition = new Point(...);
// define properties here
f.Controls.Add(tb);


Just do this for all controls and I think your form will work.

Cheers.
:rose:
 
Share this answer
 
I presume you are using Windows Forms?

It is indeed possible. Controls are just objects of a particular class. Look at your Form1.Designer.cs file. This is how the designer persists the controls on your form. It's just normal C#.

Be wary about creating too many controls on one form, though. And don't forget to call myForm.Controls.Add( myNewControl ) when you have created the new controls.

Nick
 
Share this answer
 

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