請問各位:
每次在勾選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);
}
每次在勾選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);
}
并不表示打勾的那个项目如果要表示打勾的项目,需要使用checkedListBox1.CheckedItems
{
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) {
}