Using a data source to bind data to a list

public static List<string> users=new List<string>(); ... ListBox1.DataSource = Class1.users; 

I have a ListBox, and I would like to populate it with values ​​from the collection. I try this, but the list just does not fill out, what else do I need to do?

+4
source share
3 answers

After setting up the data source, you need to bind the data:

 ListBox1.DataBind(); 

If you do not set the ListBox.DisplayMember property, the binding will use your ToString() objects for the text of the element. In your case, when you use List, you do not need to install DisplayMember .

+3
source

you need to do it

 ListBox1.DataSource = Class1.users; ListBox1.DataBind(); 

if you do not call it after collecting the collection

+1
source

Link data with

 public static List<string> users=new List<string>(); ... ListBox1.DataSource = Class1.users; ListBox1.DataBind() 
0
source

Source: https://habr.com/ru/post/1444356/


All Articles