private void button1_Click(object sender, EventArgs e)
        {            CustomNameForm cnForm = new CustomNameForm();
            DialogResult lFormResult = cnForm.ShowDialog();
            if (lFormResult == DialogResult.OK)
            {
                txtCustomName.Text = cnForm.sSName;
                this.listBox1.Items.Clear(); //清空listbox
                string gCname = custom_m.GetCname(txtCustomName.Text);
                string gEname = custom_m.GetEname(txtCustomName.Text);                MyItemlist obj1 = new MyItemlist();
                string[] arrCName = gCname.Split(',');
                string[] arrEName = gEname.Split(',');
                for (int i = 0; i < arrEName.Length; i++)
                {
                    obj1.Text = arrCName[i].ToString();
                    obj1.Value = arrEName[i].ToString();
                    listBox1.Items.Add(obj1);
                    foreach (Control ctl in this.Controls)
                    {
                        if (ctl is CheckBox)
                        {
                            if (((CheckBox)ctl).Text == obj1.Text)
                            {
                                ((CheckBox)ctl).Checked = true;
                            }
                        }
                    }
                }
            }
我想按那个button把刚刚已选的checkbox改为未选中,怎么弄啊?新手,大家帮忙一下,谢谢!

解决方案 »

  1.   

    ((CheckBox)ctl).Checked = true;要是改为未选中,是不是应该为false啊!
      

  2.   

    ((CheckBox)ctl).Checked = false;就可以了啊,有什么问题吗?
      

  3.   

    foreach (Control ctl in this.Controls)
      {
      if (ctl is CheckBox)
      {
        if (((CheckBox)ctl).Text == obj1.Text)
      {
      ((CheckBox)ctl).Checked = false;
      }
      }
      }
      

  4.   

     是当我点击那个BOTTON时,刚刚被选的CHECKBOX怎么清空?
      

  5.   

    你的checkbox有一个还是多个?
      

  6.   

    checked属性选中 为 true
    取消选中 为 false直接赋值使用,一试便知