C# 如何在组合框中显示多个项目?
我试图在combobox中显示多个项目,但在C winform中显示错误和代码不可读 我的班级C# 如何在组合框中显示多个项目?,c#,sql-server-2012,C#,Sql Server 2012,我试图在combobox中显示多个项目,但在C winform中显示错误和代码不可读 我的班级 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Booking_Management {
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;
}
}
}
然后我将其添加到winform代码编辑器中的combobox中
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
}
}
}
}
有人能帮我吗
我需要在combobox中显示,当用户鼠标单击下拉的combobox时,它包含两列,如col_EmployeeID和col_fullname。
这个源代码可能与我的目标匹配吗?我想你可能想考虑使用一个列表框控件。