2011-06-23 6 views
2
foreach (CheckedListBox item in itemInfoCheckList.Items) 
      { 
       if (item.CheckState == CheckState.Checked) 
        SW.WriteLine(item.Text + " : YES"); 
       else 
        SW.WriteLine(item.Text + " : NO"); 
      } 

それはループここで上記のコードは...わずか2つの項目 あるが以下iteminfochecklist定義C#が:ループは永遠にCheckedListBox項目をforeachの

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; 
+3

'itemInfoCheckList'を定義/生成するコードを表示してください。ループだけでは推測以外のことはできません。 –

+2

質問はどこですか? – Reniuz

+3

そのコードは無限ループに入りません。それはどうやって決めていますか? –

答えて

2

の代わりに、このコードは

foreach (CheckedListBox item in itemInfoCheckList.Items) 

使用このコード

foreach (Object item in itemInfoCheckList.CheckedItems) 
関連する問題