Get list of items from a listbox

Asked

Viewed 306 times

-1

I am creating a windows form in C# with a listbox and I would like the information saved inside this listbox to be saved in a list to be used in another class.

1 answer

1

Very simple, the listBoxalready control itself contains the list(listbox.Items)... if you still want to transfer them to a list specify just create the list and assign the listbox items to it.

 var MinhaLista= listBox.Items.Cast<String>().ToList();

if the listbox is monetary, integer or any other type, simply modify the cast to the desired type, Example(int):

var MinhaLista= listBox.Items.Cast<Int>().ToList();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.