C# : Boucle pour toujours foreach CheckedListBox élément

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

Le code ci-dessus est extrait de où il de boucles ... bien qu'il y a seulement 2 articles
Ci-dessous est la iteminfochecklist définition

 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;
  • Merci de nous montrer le code qui définit / remplit itemInfoCheckList. Il est impossible de faire autre chose que des conjectures compte tenu de la boucle seul.
  • Ce code ne va pas aller dans une boucle infinie. Comment allez-vous déterminer qui il est?
  • Plus probablement, vous obtiendrez exception lorsque vous essayez de lancer itemInfoCheckList.Items à CheckedListBox