Solved

Binding Winform DropdownList or ListBox

Posted on 2007-03-30
1
1,533 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

Industry Leaders: 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

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 article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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