Binding a generic List to a ComboBox

后端 未结 6 1559
轻奢々
轻奢々 2020-12-16 13:07

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

6条回答
  •  不思量自难忘°
    2020-12-16 13:46

    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 Months = new List
    {
       "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());
    
        

    提交回复
    热议问题