Re: Dynamic form build...
You should create a UserControl that contains that set of child controls. You can then add an instance of that UserControl in a single operation to add the entire set of child controls.
You should then add a TableLayoutPanel to your form. You can then simply add a new instance of your UC to that and it will grow appropriately. You can then resize your form by the same amount that the TLP resized itself. I will be something like:
vb.net Code:
Dim oldHeight = myTLP.Height
myTLP.Controls.Add(New SomeUserControl)
Me.Height += myTLP.Height - oldHeight
That's all there is to it. You can then get each UC by index from the TLP.
Another alternative, depending on the circumstances, might be to use the DataRepeater control.
Re: Dynamic form build...
Hi jmcilhinney,
Thanks for your help, I have got this working now, I do however have a couple of questions.
1) I am still unclear how I can tell if the user has clicked on the '-' button on the usercontrol. What I want to do is if the user clicks the '-' button then it removes the corosponding usercontrol.
2) I also need to get the value of all of the coboboxs on the various usercontrol, therefore I need to loop through the usercontrols on the form and get each value, not sure how to do this.
Any help would be really apreshiated
Thanks
Simon
Re: Dynamic form build...
1. Handle the Button's Click event as normal. From there you have a couple of choices. You could either have the UC Remove itself from its Parent's Controls collection, or you could have the UC raise an event that the form can handle and it can Remove the UC.
2. Like all controls, the TLP has a Controls collection. You loop through that to get eacg child, i.e. your UCs.