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針對單擊選擇的項  一定要注意哦!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM