c# - 如何以编程方式取消选中checkedListBoxin ac#表单中的复选框?
问题描述
我想编写一个方法,根据条件,仅取消选中 c# 中复选框列表中的某个复选框。我已经为变量“money”分配了一个值,确定了列表中复选框的索引,并为它的值分配了一个名为“index”的全局变量。此外,为checkedList Name 输入的字符串与checkedListBox 的名称相同。
这是我的代码:
public void updateResources(String checkedListName, int cost)
{
if (money < cost)
{
if (checkedListName == "checkedListBoxBasics")
{
//uncheck box at index
}
else if (checkedListName == "checkedListBoxConstruction")
{
//uncheck box at index
}
//... more else if statements
}
else
{
//implement input variables with other external variables
}
}
解决方案
如果您已经知道需要更改状态的 Checkbox 的索引,则可以使用CheckListBox.SetItemCheckState方法。例如,
checkedListBoxBasics.SetItemCheckState(index, CheckState.Checked);
或取消选中
checkedListBoxBasics.SetItemCheckState(index, CheckState.Unchecked);
推荐阅读
- sql - 如何使用sql在oracle中的一对一映射中查找重复项?
- c# - 在解决方案中引用项目或程序集的最佳实践
- powerbi - DAX ALLEXCEPT 按多维表的类别求和
- c# - 使用新的 .NET SDK Azure.Messaging.EventHubs 使用 EventProcessorClient 进行检查点
- azure - 具有内部 IP 地址的天蓝色功能或 Web 服务
- java - 我正在尝试制作一个列出平方数的循环。我的 Java 代码有什么问题?
- node.js - Angular 项目没有满足我的要求
- r - 匹配和替换 R 中的行名
- pandas - 在pandas中取消堆叠数据框后的堆叠是不同的
- r - 使用向量中的相关位置来查找索引