string strValue = "abc";
            foreach (CheckBox c in CheckedListBox.Controls)
            {
                string chkValue = c.Text;
                if (strValue.IndexOf(chkValue) >= 0)
                {
                    c.Checked = true;
                }
            }调试发现Controls为0,但实现有4个CheckBox ,请问如何处理?

解决方案 »

  1.   

    CheckedListBox的实现机制并非你所想像的那样
    参考以下代码             this.checkedListBox1.Items.Clear();
                foreach (char s in "abigcat")
                {
                    this.checkedListBox1.Items.Add(s);
                }            string strValue = "abc";
                for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
                {
                    string chkValue = this.checkedListBox1.Items[i].ToString();
                    if (strValue.IndexOf(chkValue) >= 0)
                    {
                        this.checkedListBox1.SetItemChecked(i, true);
                    }
                }