Search code examples
c#foreachcheckedlistbox

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.


Solution

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