How to displaying multiple items in combobox?

时间:2018-07-25 04:59:46

标签: c# sql-server-2012

I try to display multiple items in combobox but it error and code unreadable in C# winform.

My classs

       using System;
       using System.Collections.Generic;
       using System.Linq;
       using System.Text;
       using System.Threading.Tasks;

      namespace Booking_Management
      {
          public class classcombobox
      {
          public string EmployeeID { get; set; }
          public string FullName { get; set; }
          public string symbol { get; set; }
          public classcombobox(string EmployeeID, string FullName)
      {
        this.EmployeeID = EmployeeID;
        this.FullName = FullName;
      }
    }
  }

then I add it to combobox in winform code editor

    private void loadstaff()
    {
        string staff = "select EmployeeID, Name, Surname from tb_employee";
        DataTable dt = ClassConnection.DataParent(staff, "tbname");
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow item in dt.Rows)
            {
                cmbeid.Properties.Items.Clear();
                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    List<classcombobox> cmb = new List<classcombobox>();

                    //adding item from tabble to combobox                        
                    cmb.Add(new classcombobox(dt.Rows[i][0], dt.Rows[i][1] + dt.Rows[i][2])); /// Can not read. I don't know why? 

                     //use DevExpress ComboboxEdit
                    cmbeid.Properties.ItemSource = cmb; // itemsource unreadable by the system

                    //Try in System comboBox
                    comboBoxitem.ItemSource = cmb; //this the system also can not read 

                }
            }
        }
    }

Any body can help me?

I need to display in combobox as when user mouse click the combobox droppeddown and on the dropdown box it contains two columns like col_EmployeeID and col_fullname. Is this source code possible to match my aim?

0 个答案:

没有答案