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 !!
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 !!
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
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;