Binding a generic List<string> to a ComboBox

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.


this is the simple way (it works correctly):

List<string> my_list = new List<string>();
my_list.Add("item 1");
my_list.Add("item 2");
my_list.Add("item 3");
my_list.Add("item 4");
my_list.Add("item 5");
comboBox1.DataSource = my_list;

Here is a rather simple way that doesn't use BindingSource:

first, add the generic list of string, perhaps to a "consts/utils" class:

public static List<string> Months = new List<string>
{
   "Jan",
   "Feb",
   "Mar",
   "Apr",
   "May",
   "Jun",
   "Jul",
   "Aug",
   "Sep",
   "Oct",
   "Nov",
   "Dec"
};

And here's how you add those strings to a combo box:

comboBoxMonth.Items.AddRange(UsageRptConstsAndUtils.Months.ToArray<object>());