How do I add the elements of a Liststring to a listBox? [closed]

-1

I have a List in a class, and in the main class I want to get this List and add its elements in a listBox and then display them. How do I do that? Thanks !!

    
asked by anonymous 14.05.2016 / 21:14

2 answers

0

Here is the answer to anyone who has similar questions:

foreach (var p in obterPares.pares)

    {
         listBoxParesGerados.Items.Add(p);
    }

The p in foreach will go through each element of the list, then, using the Add of the listBox, add p

    
14.05.2016 / 23:07
2

You can use the DataSource property.

List<string> lista = new List<string>();
lista.Add("Nome 1");
lista.Add("Nome 2");
lista.Add("Nome 3");
listBox.DataSource = lista;
    
15.05.2016 / 05:12