【问题标题】:How to set checked item in checkedlistbox with listbox - c# [closed]如何使用列表框在checkedlistbox中设置选中的项目-c# [关闭]
【发布时间】:2017-02-21 13:21:34
【问题描述】:

我无法从listbox 中选择项目并检查checkedlistbox 中的项目。

如何从listbox 中选择项目,然后签入checkedlistbox

我无法选择列表框项并在匹配项时检查已选中的列表框

我想要列表框中的项目时选择复选框的代码

如何用文本框和逗号分隔签入checkedlistbox

【问题讨论】:

    标签: c# listbox checked checkedlistbox checkeditems


    【解决方案1】:

    如果我理解你的问题:

    你需要的是GetItemCheckState方法。

    用法如下:

    试试这个:

      foreach (var item in listBox1.Items)
            {
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    checkedListBox1.SetItemChecked(i, false);//First uncheck the old value!
                                                             //
                    for (int x = 0; x < listBox1.Items.Count; x++)
                    {
                        if (checkedListBox1.Items[i].ToString() == listBox1.Items[x].ToString())
                        {
                            //Check only if they match! 
                            checkedListBox1.SetItemChecked(i, true);
                        }
                    }
                }
    
    
            }
    

    【讨论】:

    • 不,我想在项目在列表框中时设置检查
    • 你能澄清这个问题,以便我可以根据这个编辑答案吗?
    • 我不知道如何解决这个问题
    • 我想要在列表框中的项目时选择复选框的代码
    • values.Length 不在我的项目中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    相关资源
    最近更新 更多