C# CheckedListBox中的选中项

C# CheckedListBox中的选中项,c#,winforms,boolean,checkedlistbox,C#,Winforms,Boolean,Checkedlistbox,在C#中,如果我有CheckListBoxItem的文本,如何确定是否选中了checklistbox中的项目 我需要遍历所有CheckedListBoxItems,并检索文本和选中状态 以下是我到目前为止的情况: CheckedListBox.ObjectCollection items = checkedListBoxFileNames.Items; foreach (var item in items) { } 我不确定如何确定是否检查了项目 提前感谢。您可以使用like IEnumer

C#
中,如果我有
CheckListBoxItem
的文本,如何确定是否选中了
checklistbox
中的项目

我需要遍历所有
CheckedListBoxItems
,并检索文本和选中状态

以下是我到目前为止的情况:

CheckedListBox.ObjectCollection items = checkedListBoxFileNames.Items;
foreach (var item in items)
{

}
我不确定如何确定是否检查了项目

提前感谢。

您可以使用like

IEnumerable<int> allChecked = (from item in chkBoxList.Items.Cast<ListItem>() 
                           where item.Selected 
                           select int.Parse(item.Value));
IEnumerable allChecked=(来自chkBoxList.Items.Cast()中的项)
其中项目。已选定
选择int.Parse(item.Value));
更多详细信息

请尝试以下操作:

foreach(object itemChecked in checkedListBox1.CheckedItems)
{
     //your code
}
也检查

此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.

你需要所有的检查项目吗?您可以使用CheckedItems属性