1.添加项
checkedListBox1.Items.Add("蓝色");
checkedListBox1.Items.Add("红色");
2. 判断第i项是否选中
if(checkedListBox1.GetItemChecked(i))
{
}
else
{
}
3. 设置第i项是否选中
checkedListBox1.SetItemChecked(i, true);
checkedListBox1.SetItemChecked(i, false); //未选中
4. 设置全选
添加一个名为select_all的checkbox控件,由其控制checkedListBox是全选还是全不选。
private void select_all_CheckedChanged(object sender, EventArgs e)
{
{
}
else
{
for (int j =0; j < checkedListBox1.Items.Count; j++)
}
}
5.得到全部选中的值 ,并将选中的项的文本组合成为一个字符串。
checkedListBox1.Items[i]);
GetItemText(checkedListBox1.Items[i]);
}
6.设置CheckedListBox中第i项的Checked状态
checkedListBox1.SetItemCheckState(i, CheckState.Checked);
7.
private void checkBoxAll_CheckedChanged(object sender, EventArgs e)
{
checkedListBoxLayerContr
}
}
else
{
{
checkedListBoxLayerContr
}
}
}
8. checkedListBox 单选设置(代码实现)
private void chkl_ItemAuditing_ItemCheck(object sender,
ItemCheckEventArgs e)
{
if (i != e.Index)
{
this.chkl_ItemAuditing.SetItemCheckState(i,
System.Windows.Forms.CheckState.Unchecked);
}
}
}
}
9. checkedListBox1显示一个数据库中关键字对应的所有记录
for (int i = 0; i < table.Rows.Count; i++)
{
}
10.
for(i=0;i
{
CheckedListBox.Items)=="你得到的值")
{
}
}
11. 清除checkedListBox1中所有的选项
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
}
12. //设置索引为index的项为选中状态
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
}
13.
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetSelected(i))
{
MessageBox.Show(checkedListBox1.CheckedItems.ToString());
}
}
14.//选中checkedListBox1所有的选项
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemCheckState(i, CheckState.Checked);
}
15.
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
//如果checkedListBox1的第i项被选中,
//则显示checkedListBox1对应的值
if (checkedListBox1.GetItemChecked(i))
{
}
}
16. //反向选择checkedListBox1的选项
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
}
17. //checkedListBox1中选定的项->checkedListBox2
for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
{
//remove是除去一个具体的值,不是index,注意了
}