foreach (CheckedListBox item in itemInfoCheckList.Items)
            {
                if (item.CheckState == CheckState.Checked)
                    SW.WriteLine(item.Text + " :  YES");
                else
                    SW.WriteLine(item.Text + " : NO");
            }


上面的代码段是循环的地方...尽管只有2个项目
以下是iteminfochecklist的定义

 this.itemInfoCheckList.CheckOnClick = true;
        this.itemInfoCheckList.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.itemInfoCheckList.FormattingEnabled = true;
        this.itemInfoCheckList.Items.AddRange(new object[] {
        "item 1 ",
        "item 2"});
        this.itemInfoCheckList.Location = new System.Drawing.Point(573, 350);
        this.itemInfoCheckList.Name = "itemInfoCheckList";
        this.itemInfoCheckList.Size = new System.Drawing.Size(197, 38);
        this.itemInfoCheckList.TabIndex = 143;

最佳答案

代替此代码

foreach (CheckedListBox item in itemInfoCheckList.Items)


使用此代码

foreach (Object item in itemInfoCheckList.CheckedItems)

关于c# - C#:永远循环foreach CheckedListBox项目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6459737/

10-10 23:44