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

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

3 Answers 3

3

After setting 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 objects ToString() method for the item text. In your case, as you are using List, you do not need to set DisplayMember.

Sign up to request clarification or add additional context in comments.

Comments

1

you need to do like this

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

if not call it after assingning collection

1 Comment

There is no need to set those properties as it is a List<string>.
0

Bind the Data using the

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.