Dynamic form build...

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I really don't know where to start with this, I want to create a form dynamically.

I have a section on the form that has 3 combobox and 2 buttons. What I want is when the user clicks on the '+' button it add another 3 combobox and 2 buttons below the first, and so on and so on. Also when the user clicks the '-' button I want to remove the row of 3 combobox etc.

I have attached an image to try and illistrate further.

Thanks for the help

Simon
 
This is easiest done with a UserControl that you add your set of controls to. Now you can add multiple instances of the UserControl to form. In form it is probably easiest managed with a FlowLayoutPanel to hold the UCs.

Another option is the DataGridView control, that support both ComboBox and Button Columns, then you just change number of rows.
 
In the ADD button click event

->Create new instance of the controls which you want to add.
->Give unique name. (Eg: ControlName.Name=”anything” & staticIncrimentableVariable)
->set the location.
->And finally add it to the form. [Me.controls.Add(ControlName)]

To Remove:

->Create new instance of the controls which you want to remove.
->Assign the name of the control(Eg: ControlName.Name=Me.controls.Item(”anything” & staticIncrimentableVariable)
->Finally remove it from the form. [Me.Controls.Remove(ControlName)]
 
Back
Top