c# checklistbox的用法 2007-10-30 16:00
1、添加項:
checkedListBox1.Items.Add("藍色");
checkedListBox1.Items.Add("紅色");
checkedListBox1.Items.Add("黃色");
2、判斷第0項是否選中
if (checkedListBox1.GetItemChecked(0))
3、設定第0項是否選中
checkedListBox1.SetItemChecked(0, true);
4、設定全選
添加一名為select_all的checkbox控制項
private void select_all_CheckedChanged(object sender, EventArgs e)
{
if(select_all.Checked)
for (int j = 0; j < checkedListBox1.Items.Count; j++)
checkedListBox1.SetItemChecked(j, true);
else
for (int j =0; j < checkedListBox1.Items.Count; j++)
checkedListBox1.SetItemChecked(j, false);
}
5、得到全部選中的值:
private void linkLabel_yes_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
panel_friend.Visible = false;
button_friend.Text = "好友面板";
sms_str = null;
for (int j = 0; j < checkedListBox1.Items.Count; j++)
//sms_str = sms_str + checkedListBox1.SelectedItems[j].ToString().Substring(4,11);//特別注意是[j]不是(j)
if(checkedListBox1.GetItemChecked(j))
sms_str = sms_str + checkedListBox1.Items[j].ToString();
sms_content.Text = sms_str;
}