Solved

Binding Winform DropdownList or ListBox

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now