简体   繁体   English

如何使清单框的所有项目都列出C#?

[英]How to get all items of checklistbox to list c#?

I tried below code but does not work. 我尝试了下面的代码,但不起作用。

  checkedListBox1.Items.OfType<String>().ToList();

it is working for selected items, but does not work for this. 它适用于选定的项目,但不适用于此项目。 Is there any other way by not using any loop? 有没有通过不使用任何循环的其他方法?

Items should work for all items, SelectedItems just for those that are selected 项目应适用于所有项目,SelectedItems仅适用于选定的项目

var allItems = checkedListBox1.Items.OfType<String>().ToList();

Use SelectedItems for items currently selected (as in, which are currently highlighted): 将SelectedItems用于当前选中的项目(如当前突出显示的内容):

var selectedItems = checkedListBox1.SelectedItems.OfType<String>().ToList();

To get items currently checked: 要获取当前已检查的项目:

var checkedItems = checkedListBox1.CheckedItems.OfType<String>().ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM