Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 770
Gilad Naaman Avatar asked Aug 02 '10 17:08

Gilad Naaman


2 Answers

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.

like image 104
Greg Bogumil Avatar answered Nov 17 '22 03:11

Greg Bogumil


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

like image 32
Manoj Nayak Avatar answered Nov 17 '22 04:11

Manoj Nayak