【发布时间】:2016-11-30 12:03:57
【问题描述】:
我尝试使用实体框架填写ComboBox
所以我试试这个:
public home()
{
InitializeComponent();
SMSEntities sms = new SMSEntities();
Item_head.DataSource = sms.spget_head().ToString().ToList();
Item_head.DisplayMember = "S_stockhead";
Item_head.ValueMember = "S_stockhead_id";
}
但这在这一行显示错误:Item_head.ValueMember = "S_stockhead";
错误:
无法绑定到新的显示成员
【问题讨论】:
-
sms.spget_head().ToString().ToList()?这是什么?确保返回的对象具有 properties 而不是字段。 -
请为您的模型发布代码 - 这会有所帮助。 S_stockhead 需要成为您的 POCO 的财产,
-
请删除
().ToString().ToList();并只留下Item_head.DataSource = sms.spget_head();您翻阅了您的列表,ComboBox找不到属性S_stockhead,因为它与最初的类型不同。