請問各位:
每次在勾選checkedlsitbox時, 即使取消後, 再勾選, messagebox的listbox1.selecteditem.tostring 仍會秀出前次已被取消的項目, 是哪個部份有問題嗎?messagebox 語法如下:
MessageBox.Show("清單有" + listBox1.Items.Count.ToString() + "\r\n選擇的是" + listBox1.SelectedItem.ToString() + "\r\n" + s);取消勾選項目語法為:
listBox1.ClearSelected();            
checkedListBox1.ClearSelected();
for (int i = 0; i <= (checkedListBox1.Items.Count - 1); i++)
{
   checkedListBox1.SetItemChecked(i, false);
}

解决方案 »

  1.   

    楼主,对于checkedListBox,其SelectedItem表示当前项目,即鼠标选择的并且高亮的那个
    并不表示打勾的那个项目如果要表示打勾的项目,需要使用checkedListBox1.CheckedItems
      

  2.   

    private void checkedListBox1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)   
      {   
      if(e.NewValue==CheckState.Checked)   
     {MessageBox.Show("Checked it"); }  
      }   
       
    string s=String.Empty;
    for (i = 0; i <=checkedListBox1.Items.Count-1; i++)
    {
      if(checkedListBox1.GetItemChecked(i))
      {
        s = checkedListBox1.Items[i].Value+",";
      }
    }
    foreach(object item in checkedListBox1.Items) {
        }