combobox1 combobox2 combobox3 combobox4 combobox5 ........使用如下语句
foreach(Control control2 in this.Controls)
if(control2 is CheckBox)
{
CheckBox chebox = control2 as CheckBox;
if( chebox.Checked == true)
Txt += chebox.Text.Trim() + ";";
}
如果北选中现在我想按顺序的把他的text给取出来,如combobox1没有选中2,6选中了,则按2在先6在后的顺序将其text赋给Txt
紧急求救

解决方案 »

  1.   

    不知所云
    一下是checkbox一下是combobox
      

  2.   

    用foreach本身就是从上到下,从头到尾按顺序来的
      

  3.   

    我写的 时候大意了,我的排列是这样的
    checkbox1  checkbox4 checkbox7
    checkbox2  checkbox5 checkbox8
    checkbox3  checkbox6 checkbox9
    想按1,2,3,4,5,6,7,8,9的顺序来判断是否选择了然后取其text 赋给txt
    这么做到啊望指点
      

  4.   

    名称是有规律的吧?用FindControl方法。
      

  5.   

     List<string> list = new List<string>();
                foreach (Control c in this.Controls)
                {
                    if (c is CheckBox && ((CheckBox)c).Checked)
                    {
                        list.Add(c.Text);
                    }
                }
                list.Sort();
                foreach (string s in list)
                {
                    txt.Text += s;
                }
    我运行过 可以成功
      

  6.   

    应该是 list.Add(c.Name); 
      

  7.   

    楼上法子不错
    至于.text或 .name,就看你 自己想要什么了