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 ,请问如何处理?
foreach (CheckBox c in CheckedListBox.Controls)
{
string chkValue = c.Text;
if (strValue.IndexOf(chkValue) >= 0)
{
c.Checked = true;
}
}调试发现Controls为0,但实现有4个CheckBox ,请问如何处理?
参考以下代码 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);
}
}