Solved

Binding Winform DropdownList or ListBox

Posted on 2007-03-30
1
1,526 Views
Last Modified: 2008-02-01
Hi
Need an example to bind to winform DropdownList or ListBox.

Thanks
0
Comment
Question by:AdibRahman77
[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 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 18827818
here is an example where i bind a class Employee list's object to a combobox and listbox

public class EmployeeList
    {
        ArrayList FEmployee = null;

        public event ListChangedEventHandler ListChanged;
               
        public EmployeeList()
        {
            FEmployee = new ArrayList();
            FEmployee.Add(new Employee("1", "Joe"));
            FEmployee.Add(new Employee("2", "Joe2"));
            FEmployee.Add(new Employee("3", "Joe3"));
            FEmployee.Add(new Employee("4", "Joe4"));
            //FEmployee =
            //    new Employee[]{new Employee("1","Joe"),new Employee("2","Joe")
            //        ,new Employee("3","Joe"),new Employee("4","Joe")
            //    ,new Employee("5","Joe"),new Employee("6","Joe"),new Employee("7","Joe")};
        }
        public ArrayList Employees
        {
            get
            {
                return FEmployee;
            }
        }
        public void ChangeEmployeeList()
        {
            ((Employee)FEmployee[0]).Name = "Gautham";
            if (ListChanged != null)
            {
                // ListChanged(this, ListChangedEventArgs.Empty);
            }
        }
    }
    public class Employee
    {
        string FName;
        string FID;
        public Employee(string ID, string Name)
        {
            FName = Name;
            FID = ID;
        }
        public string Name
        {
            get
            {
                return FName;
            }
            set
            {
                FName = value;
            }
        }
        public string ID
        {
            get
            {
                return FID;
            }
            set
            {
                FID = value;
            }
        }
    }



 FEmployee = new EmployeeList();
 comboBox1.DataSource = FEmployee.Employees;
            comboBox1.ValueMember = "Id";
            comboBox1.DisplayMember = "Name";

            listBox1.DataSource = FEmployee.Employees;
            listBox1.ValueMember = "Id";
            listBox1.DisplayMember = "Name";


same can be binded to a datatable by assigingthe datasource property to the datatable and the value and displaymembers to the respective columns in the datatable
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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