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;
}