views:

1371

answers:

2

I have a combo box 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 combo box 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!

+4  A: 

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.

Yuriy Faktorovich
Where is .DataBind at? It doesn't show up in intellisense as an option.
Nathan
It is for web forms, for win forms your answer should work. There is something wrong in another part of your program. If you isolate your code, it should work.
Yuriy Faktorovich
I just did more digging and found a buried exception which from reason did bubble up. Thanks everyone.
Nathan
A: 

I have just posted a code for something similar to that, check the link below

http://stackoverflow.com/questions/1609984/c-winform-possible-combobox-with-2-datasources-diffrentiated-by-colored-text/1610910#1610910

madan