Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Binding Winform DropdownList or ListBox

Posted on 2007-03-30
1
Medium Priority
?
1,539 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 1500 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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

664 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