Hi all,

I am generating comboboxes in runtime in a for loop.
Then, when click ok i want to get the selectedItems.

So how would i do this.
PLZ help me.
this is how i generate comboboxes in th page load.

NewBookEntry nbe = (NewBookEntry)Application.OpenForms["NewBookEntry"];
            int lable = 0;

 for (int c = 0; c < int.Parse(nbe.TextBox2.Text); c++)
            {
                ComboBox ioj = new ComboBox();
                ioj.Items.AddRange(new object[] {
            "Good",
            "Medium Damaged",
            "Highly Damaged"});

                ioj.SelectedIndex = 0;

                tableLayoutPanel1.Controls.Add(ioj, 1, c);

Recommended Answers

All 2 Replies

Define a List (or array) of ComboBoxes as a (private) member of your class and fill it in your for-loop. Then in your Button-Click event handler iterate over the List and obtain the selected value with currentComboBox.SelectedItem.Text;

Define a List (or array) of ComboBoxes as a (private) member of your class and fill it in your for-loop. Then in your Button-Click event handler iterate over the List and obtain the selected value with currentComboBox.SelectedItem.Text;

Thank you a lot.
It works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.