当前位置: 首页 > article >正文

C#高级:Winform桌面开发中CheckedListBox的详解

一、基础设置

单击触发选择效果:需要选择下面这个为True

二、代码实现

1.设置数据源

/// <summary>
/// 为CheckBoxList设置数据源
/// </summary>
/// <param name="checkedListBox1"></param>
/// <param name="data"></param>
private void SetCheckListSource(CheckedListBox checkedListBox1, List<string> data)
{foreach (var item in data){checkedListBox1.Items.Add(item);}
}

2.设置全选和取消全选

/// <summary>
/// 全选和取消全选(True=全选)
/// </summary>
private void SetCheckListAllStatus(CheckedListBox checkedListBox1, bool v)
{for (int i = 0; i < checkedListBox1.Items.Count; i++){checkedListBox1.SetItemChecked(i, checkBox1.Checked);}
}

3.获取选中项目和非选中项目

/// <summary>
/// 获取CheckedListBox数据(True=获取选中的项目,False=获取未选中的项目)
/// </summary>
private List<string> GetCheckedListBoxData(CheckedListBox checkedListBox1, bool isSelect=true)
{List<string> result = new List<string>();for (int i = 0; i < checkedListBox1.Items.Count; i++){bool isChecked = checkedListBox1.GetItemChecked(i);// 根据 isSelect 的值来决定是获取选中的项目还是未选中的项目if (isSelect){if (isChecked)result.Add(checkedListBox1.Items[i].ToString());}else{if (!isChecked)result.Add(checkedListBox1.Items[i].ToString());}}return result;
}

http://www.lryc.cn/news/2386675.html

相关文章:

  • 【Java学习笔记】final关键字
  • AI学习笔记二十八:使用ESP32 CAM和YOLOV5实现目标检测
  • 免费分享50本web全栈学习电子书
  • 【prometheus+Grafana篇】基于Prometheus+Grafana实现MySQL数据库的监控与可视化
  • 全链路解析:影刀RPA+Coze API自动化工作流实战指南
  • 高阶数据结构——哈希表的实现
  • window 显示驱动开发-报告渲染操作的可选支持
  • 2025 年网络安全趋势报告
  • uniapp 条件筛选
  • pytorch问题汇总
  • 开发过的一个Coding项目
  • 数据仓库维度建模详细过程
  • python打卡day37
  • Redis 5.0.10 集群部署实战(3 主 3 从,三台服务器)
  • 各个网络协议的依赖关系
  • OSC协议简介、工作原理、特点、数据的接收和发送
  • 区块链可投会议CCF C--APSEC 2025 截止7.13 附录用率
  • 【数字图像处理】_笔记
  • 从0开始学习R语言--Day10--时间序列分析数据
  • 基于开源链动2+1模式AI智能名片S2B2C商城小程序的产品驱动型增长策略研究
  • 每日算法 -【Swift 算法】反转整数的陷阱与解法:Swift 中的 32 位整数处理技巧
  • 使用 OpenCV 实现“随机镜面墙”——多镜片密铺的哈哈镜效果
  • 鸿蒙仓颉开发语言实战教程:页面跳转和传参
  • 如何在Vue中实现延迟刷新列表:以Element UI的el-switch为例
  • 最新Spring Security实战教程(十六)微服务间安全通信 - JWT令牌传递与校验机制
  • MDM在智能健身设备管理中的技术应用分析
  • OSPF ABR汇总路由
  • 【五】Spring Cloud微服务开发:解决版本冲突全攻略
  • Spring Boot微服务架构(二):开发调试常见中文问题
  • Linux基础IO----动态库与静态库