CheckedListBox 中的选中项
Checked items in a CheckedListBox
在C#
中,如果我有CheckListBoxItem
的文本,我如何确定CheckedListBox
中的项目是否被选中?
我需要遍历所有 CheckedListBoxItems
,并检索文本和选中状态。
这是我目前的情况:
CheckedListBox.ObjectCollection items = checkedListBoxFileNames.Items;
foreach (var item in items)
{
}
我不确定如何确定一个项目是否被选中。
提前致谢。
你可以像这样使用
IEnumerable<int> allChecked = (from item in chkBoxList.Items.Cast<ListItem>()
where item.Selected
select int.Parse(item.Value));
更多详情click here
这样试试:
foreach(object itemChecked in checkedListBox1.CheckedItems)
{
//your code
}
同时勾选 CheckedListBox.CheckedItems Property
Collection of checked items in this CheckedListBox.
您不需要这个 foreach 循环。
试试这个:
if(this.m_CheckedListbox.CheckedItems.Contains("Item1")
{
//make an action, if it's checked.
}
if(this.m_CheckedListbox.CheckedItems.Contains("Item2")
{
//make an action, if it's checked.
}
// etc...
// this.m_CheckedListbox should be the name of your checked list box.
在C#
中,如果我有CheckListBoxItem
的文本,我如何确定CheckedListBox
中的项目是否被选中?
我需要遍历所有 CheckedListBoxItems
,并检索文本和选中状态。
这是我目前的情况:
CheckedListBox.ObjectCollection items = checkedListBoxFileNames.Items;
foreach (var item in items)
{
}
我不确定如何确定一个项目是否被选中。
提前致谢。
你可以像这样使用
IEnumerable<int> allChecked = (from item in chkBoxList.Items.Cast<ListItem>()
where item.Selected
select int.Parse(item.Value));
更多详情click here
这样试试:
foreach(object itemChecked in checkedListBox1.CheckedItems)
{
//your code
}
同时勾选 CheckedListBox.CheckedItems Property
Collection of checked items in this CheckedListBox.
您不需要这个 foreach 循环。
试试这个:
if(this.m_CheckedListbox.CheckedItems.Contains("Item1")
{
//make an action, if it's checked.
}
if(this.m_CheckedListbox.CheckedItems.Contains("Item2")
{
//make an action, if it's checked.
}
// etc...
// this.m_CheckedListbox should be the name of your checked list box.