checkbox 是动态添加的,代码:
                CheckBox cb = new CheckBox();
                cb.Text = menulist[i].MenuName.Trim();
                cb.Name = cb + menulist[i].MenuName.Trim();
                cb.Tag = menulist[i].ID.ToString().Trim();现在要根据指定的tag先中该checkbox应该怎么做?本人菜鸟,希望神人留下代码

解决方案 »

  1.   

                    // foreach all controls in panel1
                    foreach (Control item in this.panel1.Controls)
                    {
                        // find the values of tag which related to CheckBox from menu
                        if (item.Tag.ToString().Trim() == rolelist[i].MenuID.ToString().Trim())
                        {
                            
                        }
                    }这样的情况,if里面不知道怎么处理了
      

  2.   

      foreach (Control ctl in this.Controls)
                {
                    if (ctl.Tag == "XXXX")
                    {
                       
                    }
              
                }
    那个XXXX就是你要查的tag
      

  3.   


     List<string> CheckIds;///要选中的tag
                foreach (Control ctl in this.Controls)
                {
                    foreach (string checkId in CheckIds)
                    {
                        if (ctl.Tag == checkId)
                        {
                           ( ctl as CheckBox).Checked=true;
                        }
                             
                    }
              
                }
      

  4.   


    刚刚少打了 一个字!我想问的是 你待选择的 tag 是放在哪的
      

  5.   

     ( ctl as CheckBox).Checked=true;
    谢谢解决了