我有这样的代码:如何从Entity Framework添加项目到Combobox?
private void FillCombobox()
{
using (InventoryEntities c = new InventoryEntities(Properties.Settings.Default.Connection))
{
List<Customer> usepurposes = c.Customers.ToList();
DataTable dt = new DataTable();
dt.Columns.Add("id");
dt.Columns.Add("name");
foreach (Customer usepurpose in usepurposes)
{
dt.Rows.Add(usepurpose.id, usepurpose.name);
}
comboBox1.ValueMember = dt.Columns[0].ColumnName;
comboBox1.DisplayMember = dt.Columns[1].ColumnName;
comboBox1.DataSource = dt;
}
}
,我把这种方法:当我运行我的应用程序
private void frmBillIn_Load(object sender, EventArgs e)
{
FillCombobox();
}
,组合框不会显示客户(项目)。
只是显示Model.Customer
问题是什么?
我尝试了很多解决方案,但他们都不工作。
我想你的代码,但我仍然得到同样的结果,我还试图用“名”也是同样的结果“Model.Customer” – Saleh 2012-07-31 18:10:33
你能后的类“模式的代码。顾客”? – 2012-07-31 19:02:53
我找到了解决方案,OMG,我觉得我很愚蠢,这是愚蠢的错误,无论如何非常感谢你。 – Saleh 2012-07-31 19:49:50