C#: easiest way to populate a ListBox from a List
142,658
Solution 1
Try :
List<string> MyList = new List<string>();
MyList.Add("HELLO");
MyList.Add("WORLD");
listBox1.DataSource = MyList;
Have a look at ListControl.DataSource Property
Solution 2
You can also use the AddRange
method
listBox1.Items.AddRange(myList.ToArray());
Solution 3
Is this what you are looking for:
myListBox.DataSource = MyList;
Related videos on Youtube
Author by
Craig Johnston
Updated on January 06, 2020Comments
-
Craig Johnston over 4 years
If I have a list of strings, eg:
List<string> MyList = new List<string>(); MyList.Add("HELLO"); MyList.Add("WORLD");
Is there an easy way to populate a ListBox using the contents of MyList?