Click here to Skip to main content
15,914,074 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a form in my winforms app that holds a button.When I press that button,I would like to generate one click at a time no more than 6 comboboxes from where the user can choose the desired item.I have tried to make it by using some of the explanations found on the internet,but unfortunately most of them are bound to adding an item into the combobox by pressing a button.I have found a particular example where you can press a button and for every click,another button will appear and I have tried to make the same logic for the combobox,but without any luck.Can someone help me with the logic,please?Thank you in advance!

What I have tried:

This is what I have tried:
private void bunifuFlatButton1_Click(object sender, EventArgs e)
       {
           panelRegistration.Controls.Add(comboBoxCourse);

       }
Posted
Updated 12-Jun-18 1:00am
v2

1 solution

You're basically doing it correctly already:

private void bunifuFlatButton1_Click(object sender, EventArgs e)
{
    var comboBox1 = new ComboBox();
    // Initialise comboBox1, e.g. add DataSource, Location, etc.
    panelRegistration.Controls.Add(comboBox1);
}
 
Share this answer
 
v2
Comments
Daniel Andrei Popescu 12-Jun-18 7:05am    
Thank you,Thaddeus Jones for the solution.It seemed i was doing it correctly except for the part where I continuously add comboboxes to the panel.I thought that if I add it once to the panel it would be enough.Best regards!
[no name] 12-Jun-18 7:08am    
Anytime :) The reason why that wouldn't work is that a control can only have one parent. When you add it to the panel the second time, it is first removed.
Daniel Andrei Popescu 12-Jun-18 7:12am    
Now I understand.Thank you again and also for the explanation.

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