Get list of items from a listbox [closed]

-1

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

    
asked by anonymous 21.02.2017 / 19:54

1 answer

1

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

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

If the listbox is of monetary values, integers or any other type, simply modify the cast to the desired type, Example (int):

var MinhaLista= listBox.Items.Cast<Int>().ToList();
    
01.03.2017 / 17:45