• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1172
  • Last Modified:

Display and Value member binding to a ComboBox

I am trying to bind the display and value members to a combobox from an arrayList that contains a custon Object.

I made the object "ComboItem" that holds a name and a value.  Each of these are added to the Arraylist.  The datasource line works, but it won't accept the names of the DisplayMember or the ValueMember.

What am I doing wrong?  I've already tried changing the value variable in ComboItem as an int; and changing the case of the names.


 private void MainForm_Load(object sender, EventArgs e) {      
          IList aList = new ArrayList();
            ComboItem cItemNone = new ComboItem("None", "-1");

            foreach (DataRow dr in dataSet.Tables["Students"].Rows) {
                ComboItem cItem = new ComboItem(dr[1].ToString(),dr[0].ToString());

            StudentComboBox.DataSource = aList;

            StudentComboBox.DisplayMember = "name";
            StudentComboBox.ValueMember = "value";

 private class ComboItem {
            public string Name;
            public string Value;

            public ComboItem(string name, string value) {
                Name = name;
                Value = value;
1 Solution
Use this class istead of your class

  public class ComboItem
        int _value = 0;
        string _text = string.Empty;

        public int Value
            get { return _value; }
            set { _value = value; }

        public string Text
            get { return _text; }
            set { _text = value; }
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now