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.
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.
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.
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>
toSystem.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
© 2022 - 2024 — McMap. All rights reserved.