[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Display and Value member binding to a ComboBox

Posted on 2006-11-27
1
Medium Priority
?
1,169 Views
Last Modified: 2007-12-19
Hello,
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.

thanks,
Sarah


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

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

            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;
            }
        }
0
Comment
Question by:sarahjackel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
sabeesh earned 2000 total points
ID: 18025313
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; }
        }
       
    }
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question