Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a ComboBox and I want to bind a generic List to it. Can anyone see why the code below won't work? The binding source has data in it, but it won't fill the ComboBox data source.

FillCbxProject(DownloadData Down)
{
  BindingSource bindingSource = new BindingSource();
  bindingSource.DataSource = Down.ProjectList;
  cbxProjectd.DataSource = bindingSource;
}

On a side note: Is it bad to pass around an instance of a class?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
678 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to call the Bind method:

cbxProjectd.DataBind();

If this is for winforms then you need to make sure what you have is being called, the following works:

BindingSource bs = new BindingSource();
bs.DataSource = new List<string> { "test1", "test2" };
comboBox1.DataSource = bs;

Although you can set the ComboBox's DataSource directly with the list.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...