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
Solved

Binding Winform DropdownList or ListBox

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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