假设你的listbox为listbox1,
1.首先在listbox1的items中添加"选中项","未选中项","所有项"
2在你的listbox selectindexchanged事件中添加如下代码:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox3.SelectedIndex == 0)
{
checkedListBox1.Items.Clear();
checkedListBox1.Items.Add(listBox3.SelectedItem.ToString());
}
if (listBox3.SelectedIndex == 1)
{
checkedListBox1.Items.Clear();
checkedListBox1.Items.Add(listBox3.SelectedItem.ToString());
}
if (listBox3.SelectedIndex == 2)
{
checkedListBox1.Items.Clear();
checkedListBox1.Items.Add(listBox3.Items.ToString());
checkedListBox1.Items.Add(listBox3.Items.ToString());
}
}
标签:checkedlistbox,用法