Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In following code how to get comboBox item selected by a user in the last for loop?

C#
ComboBox cmbx;
int k=0;
            for (int i = 0; i < n; i++)
            {
                cmbx = new ComboBox();
                cmbx.Name = string.Format("MyCmb_{0}", i.ToString());
		cmbxf.Text="yes";
                cmbxf.Items.Add("yes");
                cmbxf.Items.Add("no");
                tableLayoutPanel1.Controls.Add(cmbx);
            }
for (int i=0;i<m;i++)
	if (cmbx[i].SelectedItems==1) k++; ///// How to doing it????????? 
Posted

1 solution

C#
public class ClassName
{
// define list of combobox in your class 

   public List<combobox> comboboxes {get;set;}
   public ClassName()
   {
         comboboxes = new  List<combobox>();
   }
  
   private void AddItems()
   {
     // in your for loop add items to tableLayoutPanel1.Controls
     // also add the same item to comboboxes like below
     // comboboxes.Add(cmbx );  
   }
    
   private void CountItems()
   {
     // now you can check  the selected items count from comboboxes list  
   }
}</combobox></combobox>
 
Share this answer
 

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