C# CheckedListBox控件的用法總結


1. 添加項目

checkedListBox1.Items.Add("一級");
checkedListBox1.Items.Add("二級");
checkedListBox1.Items.Add("三級");

 

2. 判斷第i項是否被選中,選中為true,否則為false

if(checkedListBox1.GetItemChecked(i))
{
    return true;
} 
else
{
      return false; 
}

 

3. 設置第i項的選中狀態

checkedListBox1.SetItemChecked(i, true); //true改為false為沒有選中。

 

4. 獲取選中項的值

foreach (string outstr in checkedListBox1.CheckedItems)
{
     MessageBox.Show(outstr);
}

 

5. 遍歷選中項

for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
    if (checkedListBox1.GetItemChecked(i))
    {  
MessageBox.Show(checkedListBox1.GetItemText(checkedListBox1.Items[i]));
    }
}

 


免責聲明!

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



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