C#中ChecklistBox的部分用法

一、绑定数据

1.直接绑定,如图所示。在属性中找到Items属性,添加集合,每行为一个结果。
在这里插入图片描述
在这里插入图片描述

2.代码绑定

 checkedListBox1.Items.Add(string);

二、获取数据

1.所有值

 checkedListBox1.Items

2.获取选中值

private List<string> GetCheckedItems(CheckedListBox clb)
        {
            List<string> result = new List<string>();
            IEnumerator myEnumerator = clb.CheckedIndices.GetEnumerator();//获取选中项
            int index;
            while (myEnumerator.MoveNext())
            {
                index = (int)myEnumerator.Current;
                clb.SelectedItem = clb.Items[index];//取到选中项的值
                result.Add(clb.Text());
            }
            return result;
        }

方法二、

List<string> result =new List<String>();
for(int i =0;i<CheckedListBox.items.count;i++)
{
    if(CheckedListBox.GetItemChecked(i))
    {
        result.Add(CheckedListBox.items[i]);
    }

}

三、选中值

CheckedListBox.SetItemChecked(i,true);//i为序号,true为选中,反之则取消选中

如有其他思路或者答案,欢迎讨论

我是小赖,一个学习C#的混子。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值