C# winform CheckedListBox

CheckedListBox效果截图

在这里插入图片描述

添加项目,清空项目,项目数目

checkedListBox1.Items.Add("苹果");
checkedListBox1.Items.Add("香蕉");
checkedListBox1.Items.Add("梨子");
checkedListBox1.Items.Add("桃子");
checkedListBox1.Items.Add("菠萝");
checkedListBox1.Items.Clear();
int count= checkedListBox1.Items.Count;

检查第i项状态,选中,获取值

if(checkedListBox1.GetItemChecked(3)){
    
    
    MessageBox.Show("选中第3项");
}
checkedListBox1.SetItemChecked(3, true); //第3项选中状态为true。
//获取值
foreach (string item_str in checkedListBox1.CheckedItems)
{
    
    
    MessageBox.Show(item_str);
}

监听事件

//选中状态发生变化时调用
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    
    

}

猜你喜欢

转载自blog.csdn.net/weixin_45792450/article/details/104263890