C#中CheckListBoxes的奇怪问题
问题描述:
我正在玩的应用程序中有很多复选框。所以,我决定改用CheckedListBox。我是通过下面的代码清单遍历...C#中CheckListBoxes的奇怪问题
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);
}
}
的放出来给我这个...
System.Collections.Generic.List`1[System.String].
我很新,还从来没见过这个。应用程序运行正常,但输出不正确。有什么建议么?
答
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);
}
答
使用的foreach通过CheckedItems
foreach(string item in ServicesCheckedListBox3.CheckedItems)
{
Line.Add(item)
}
地铁迭代?的WinForms? WPF? Silverlight的? ASP.Net? MonoTouch的? – SLaks 2011-12-14 15:42:33
WinForms。在Visual Studio 2010中 – 2boolORNOT2bool 2011-12-14 15:45:13