2011-12-14 13 views
0

私が使っているアプリケーションにはかなりの数のチェックボックスがあります。だから、代わりにCheckedListBoxを使うことにしました。私は、私は非常に新しいですし、これを見たことがないC#でのCheckListBoxesの奇妙な問題

System.Collections.Generic.List`1[System.String]. 

...アウトプットは私にこれを与え

private void CheckedListBox1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if (CheckedListBox1.CheckedItems.Count != 0) 
     { 
      string x = ""; 
      for (int x = 0; x <= ServicesCheckedListBox3.CheckedItems.Count - 1; x++) 
      { 
       x = x + "Checked Item " + (x + 1).ToString() + " = " +       ServicesCheckedListBox3.CheckedItems[x].ToString() + "\n"; 
      } 
      Line.Add(x); 
     } 
    } 

...以下のコードでリストを反復します。アプリケーションは正常に動作しますが、出力は正しく出力されません。助言がありますか?

+1

メトロを反復処理するforeachのでしょうか? WinForms? WPF? Silverlight? ASP.Net? MonoTouch? – SLaks

+0

WinForms。 Visual Studio 2010の場合 – 2boolORNOT2bool

+0

最初にList を使用しているのはなぜですか? – SLaks

答えて

0
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    string x=""; 
    foreach(string chk in checkedListBox1.CheckedItems) 
    { 
     x = x + "Checked Item " + checkedListBox1.Items.IndexOf(chk).ToString() + " = " + chk + "\n"; 
    } 
    MessageBox.Show(x); 
} 
+0

これは私に同じエラーを与えます。 – 2boolORNOT2bool

+0

私は私のシステムの中で動作します。私はアイテム1を選択します。このメッセージを受け取ります。 "Checked Item 0 = i1" – MRM

+0

何か間違っている必要があります。リストを使用せずに、ハードコーディングされたタイトルを取得していますが、値は取得していません。 – 2boolORNOT2bool

0

CheckedItems

foreach(string item in ServicesCheckedListBox3.CheckedItems) 
{ 
    Line.Add(item) 
}