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

How can I create an array containing the marked elements in the selectedlist field using the foreach loop (or in any other way)?

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

+5
source share
2 answers

Assuming you are using 3.5 or higher ..

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

And if you add a specific type of object to the CheckedListBox, you can replace the object with the name of the class you are using.

+10
source

Hi, I am performing a similar task. But instead of an array, I use a list of arrays. I used the code below

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

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

, arraylist, . araay

+2

All Articles