Creating a string-array of checked items in checked-list-box

馋奶兔 提交于 2019-12-22 07:47:11

问题


How can I create an array containing the checked items in a checkedlistbox using foreach loop (or any other way)?

I can't know the number of items in the list.


回答1:


Assuming your using 3.5 or above..

object[] items = lb.CheckedItems.OfType<object>().ToArray();

And if you are adding a specific type of object to the CheckedListBox then you can replace object with the name of the class you use.




回答2:


Hi i am doing a similar kind of task . But instead of array i am using array list . I used the below code

ArrayList errorList = new ArrayList();
errorList = chklbErrorlist.CheckedItems.OfType<object>().ToList();

Cannot implicitly convert type System.Collections.Generic.List<object> to System.Collections.ArrayList

I added the items to the array and then added to the arraylist, It worked. How to add items directly to the araaylist instead of the array



来源:https://stackoverflow.com/questions/3390122/creating-a-string-array-of-checked-items-in-checked-list-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!