Click here to Skip to main content
14,936,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a dropdown list,panel and a button control in a windows form
The dropdown list items will be 1,2,3.
So when i select any of the value from dropdown list i want a panel with textbox to be created and add the dynamically created panel to the already existing panel based on the items value in dropdown
i.e., if i select 2 ,then two panels should be added to the main panel.
Can anybody help me out of this.
*** Default one panel will be static in the main panel.So when i give 2 it should have 2 panels including the one which is already present.
Thanks in advance.
Posted

Just create them, and add them to the existing Panel.Controls list:
C#
Panel p1 = new Panel();
Panel p2 = new Panel();
myPanelInMainForm.Controls.Add(p1);
myPanelInMainForm.Controls.Add(p2);
You will probably want to set the size, and location, but that's trivial...
   
Comments
Maciej Los 11-May-12 5:42am
   
OriginalGriff, if i understand, Op want to create panels dynamicly. You have showed him "static" panel creation. ;)
Would it be better to use List(of Panel)?
OriginalGriff 11-May-12 6:14am
   
Possibly - it depends on the OP application.
The trouble is that if you put too much info in, it ends up confusing rather than helping - particularly when you don't have any code to start from! :laugh:
Maciej Los 11-May-12 17:20pm
   
;)
qwerty 2 11-May-12 5:45am
   
yeah never mind ,we can use it..
Maciej Los 11-May-12 5:51am
   
@qwerty 2, if solution was helpful, please, rate it and mark as "solved". Thank you.
Wendelius 11-May-12 17:11pm
   
Exactly!
VJ Reddy 12-May-12 23:34pm
   
My 5!
I think OriginalGriff's answer is complete but just want to add a little twist. Since you're working with Forms have you noticed that you have some generated code in the ..Designer.cs? Have a look at that code and you'll notice how Visual Studio actually adds the controls on your forms. You can use the same principles in your code also :)
   
Comments
VJ Reddy 12-May-12 23:34pm
   
Good addition. 5!
Wendelius 13-May-12 2:59am
   
Thanks

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