C#遍历CheckedListBox中的勾选项
正确的代码:
string selectedItem = string.Empty; for(int i=0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { selectedItem = selectedItem + " " + checkedListBox1.Items[i].ToString(); } }
以下代码只能选择最后单击的那项
string selectedItem = string.Empty; for(int i=0; i < checkedListBox1.SelectedItems.Count; i++) { selectedItem = selectedItem + " " + checkedListBox1.SelectedItems[i].ToString(); }
checked 针对勾选 selected针对单击选择的项 一定要注意哦!