- checkedListBoxControl使用list的值成复选框的值:
-
//方式一:循环list添加 for (int i = 0; i < list.Count; i++) { checkedListBoxControl1.Items.Add(list[i]); } //方式二:资源绑定的方式 checkedListBoxControl1.DataSource = list;一键批量勾选,主要用于全选,选不选,反选
-
/*全选*/ for (int i = 0; i < checkedListBoxControl1.Items.Count; i++) { checkedListBoxControl1.SetItemChecked(i, true); }获取勾选的值
-
//checkValueList定义于List<string> checkValueList = new List<string>(); for (int i = 0; i < checkedListBoxControl1.Items.Count; i++) { if (checkedListBoxControl1.GetItemChecked(i)) { string a = checkedListBoxControl1.GetItemValue(i).ToString(); checkValueList.Add(a); } }把list数组转换成string
checkValue = string.Join(",", checkValueList.ToArray ());

本文介绍在C#中如何使用checkedListBoxControl组件,包括通过循环和资源绑定添加列表项,实现全选、反选功能,以及如何获取已勾选的值并转换为字符串。适合初学者和需要快速实现复选框列表功能的开发者。
1077

被折叠的 条评论
为什么被折叠?



