【问题标题】: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);
}
}
}
}