Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combobox Datasource not creating items

After much searching I have still not found a solution to this.

I have created a list in VS 2010 and bound it to a ComboBox. The DataSource property shows the entire list but the combobox on the form is empty, as is the items property of the box.

    private List<string> classes = new List<string>();
    private BindingList<string> bindingClasses;

        classes.Add("Spinning");
        classes.Add("Step");
        classes.Add("Pilates");
        classes.Add("Kickboxing");
        classes.Add("Body Sculpting");

        bindingClasses = new BindingList<string>(classes);
        classesComboBox.DataSource = bindingClasses;

I have also tried adding

classesComboBox.DisplayMember = "Spinning";

and without the bindingList between to no avail.

Why is this not working?

like image 568
user1774447 Avatar asked Jul 12 '26 06:07

user1774447


1 Answers

Lose the BindingList, just set the DataSource to the List<String> itself.

List<string> classes = new List<string>();
classes.Add("Spinning");
classes.Add("Step");
classes.Add("Pilates");
classes.Add("Kickboxing");
classes.Add("Body Sculpting");

classesComboBox.DataSource = classes;
classesComboBox.SelectedItem = "Spinning";
like image 110
Cole Cameron Avatar answered Jul 13 '26 20:07

Cole Cameron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!