您的位置首页百科知识

checkedlistbox用法

checkedlistbox用法

的有关信息介绍如下:

checkedlistbox用法

假设你的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());

}

}