Search code examples
c#winformslistboxcheckedlistbox

Copy items from CheckedListBox to ListBox


I'm trying to copy the CheckedItems from a CheckedListBox to a Listbox, but I am not getting it right.

I have tried

Listbox.Items.Add(checkedlistbox.CheckedItems);

but that only gives me a (collection)

Does anyone have a great line of code to share? :D


Solution

  • This should work:

    foreach(var Item in checkedlistbox.CheckedItems)
        Listbox.Items.Add(Item);
    

    Edit: replaced string with var so it works with non-string types too.