C# 在CheckedListBox上运行并检查文件中的内容

C# 在CheckedListBox上运行并检查文件中的内容,c#,winforms,C#,Winforms,我已选中包含以下内容的列表框: AA BB CC DD 我的字符串包含:CC 我需要选中CheckedListBox中的复选框CC遍历checkListBox.Items,并针对每个项目,使用myStr.Contains(item.ToString())搜索字符串中的项目,并根据包含结果将项目标记为选中或未选中 string myStr = "CC"; for (int it = 0; it < checkedListBox1.Items.Count; i

我已选中包含以下内容的列表框:

AA
BB
CC
DD
我的字符串包含:
CC


我需要选中CheckedListBox中的复选框
CC

遍历checkListBox.Items,并针对每个项目,使用myStr.Contains(item.ToString())搜索字符串中的项目,并根据包含结果将项目标记为选中或未选中

        string myStr = "CC";
        for (int it = 0; it < checkedListBox1.Items.Count; it++)
        {
            checkedListBox1.SetItemChecked(
               it, myStr.Contains(checkedListBox1.Items[it].ToString()));
        }
string myStr=“CC”;
for(int it=0;it
如果您希望在添加项目后执行此操作,下面是一个示例

private void CheckEveryOther_单击(对象发送方,System.EventArgs e){
//循环检查每一项,并检查每一项。
//将flag设置为true以了解何时执行此代码。用于ItemCheck
//事件处理程序。
Insideecheckeveryother=真;
对于(int i=0;i
private void CheckEveryOther_Click(object sender, System.EventArgs e) {
    // Cycle through every item and check every other.

    // Set flag to true to know when this code is being executed. Used in the ItemCheck
    // event handler.
    insideCheckEveryOther = true;

    for (int i = 0; i < checkedListBox1.Items.Count; i++) {

          // here you need to compare with that string....
                checkedListBox1.SetItemCheckState(i, CheckState.Indeterminate);
            else
                checkedListBox1.SetItemChecked(i, true);
        }
    }        

    insideCheckEveryOther = false;
}