void ValidateControlText(Control c)
    {
        if (c is ComboBox)
        {
            foreach (string item in b.Items)
            {
                MessageBox.Show(b.Item.ToString());
            }
        }
    }    请问各位,想要实现这样遍历ComboBox各个项的功能函数,这个foreach 遍历该如何写?

解决方案 »

  1.   

     foreach (object obj in c.Items)
                {
                    MessageBox.Show(obj.ToString());
                }
      

  2.   

    foreach   (ListItem li  in DropDownList.Items) 
    {
    response.write(li.text)
    }
      

  3.   

      foreach   (ListItem   item   in   b.Items) 
       { 
           MessageBox.Show(Item.ToString()); 
       } 
      

  4.   

    楼主,b打哪冒出来的?
    foreach       (ListItem       item       in       c.Items)  
          {  
                  MessageBox.Show(Item.ToString());  
          }  
      

  5.   

     foreach   (XXXItem  item   in   b.Items) 
      { 
        MessageBox.Show(item.对应的操作 ); 
      } 
      

  6.   

    foreach       (ListItem   li     in   DropDownList.Items)   

         \\
    }
      

  7.   


     void   ValidateControlText(Control   c) 

       if   (C.GetType() == typeof(ComboBox)) 
       { 
          foreach   (string   item   in   c.Items) 
          { 
             MessageBox.Show(item.Value); 
          } 
      } 
      

  8.   


    public List<string> GetComboBoxItems(Control c)
    {
        List<string> itemList = new List<string>();
        if (c is ComboBox)
        {
            foreach (string s in (c as ComboBox).Items)
            {
                itemList.Add(s);
            }
        }
        return itemList;
    }
      

  9.   

    foreach   (object   obj   in   c.Items) 

    foreach   (string   item   in   c.Items) 
    一样,c没有Items这个属性?
      

  10.   

    我知道楼主想问什么了,以下两种都行。
    void ValidateControlText(Control c)
    {
        ComboBox b = c as ComboBox;
        if (b != null)
            foreach (string item in b.Items)
            {
                MessageBox.Show(item);
            }
    }
    void ValidateControlText(Control c)
    {
        if (c is ComboBox)
            foreach (string item in ((ComboBox)c).Items)
            {
                MessageBox.Show(item);
            }
    }