Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#表单中以编程方式取消选中CheckedListBox中的复选框?_C#_Forms_Checkedlistbox - Fatal编程技术网

如何在c#表单中以编程方式取消选中CheckedListBox中的复选框?

如何在c#表单中以编程方式取消选中CheckedListBox中的复选框?,c#,forms,checkedlistbox,C#,Forms,Checkedlistbox,我想写一个方法,基于一个条件,只取消选中c#中复选框列表中的某个复选框。我已经为变量“money”指定了一个值,确定了列表中复选框的索引,并为其值指定了一个名为“index”的全局变量。此外,为checkedList Name输入的字符串与checkedListBox的名称相同 这是我的密码: public void updateResources(String checkedListName, int cost) { if (money < cos

我想写一个方法,基于一个条件,只取消选中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
            }
        }
public void updateResources(字符串checkedListName,int-cost)
{
如果(钱<成本)
{
如果(checkedListName==“checkedListBoxBasics”)
{
//在索引处取消选中复选框
}
else if(checkedListName==“checkedListBoxConstruction”)
{
//在索引处取消选中复选框
}
//…如果有其他声明
}
其他的
{
//使用其他外部变量实现输入变量
}
}

如果您已经知道需要更改状态的复选框索引,则可以使用方法。比如说,

 checkedListBoxBasics.SetItemCheckState(index, CheckState.Checked);
还是取消勾选

checkedListBoxBasics.SetItemCheckState(index, CheckState.Unchecked);