这是我的Dropdown DataSource:
dropReagent.DataSource =
from customerz in db.tblCustomers
select new
{
Agent = customerz.Name + " " + customerz.Family + " - " + customerz.CustomerID,
AgentID = customerz.CustomerID
};
dropReagent.DisplayMember = "Agent";
dropReagent.ValueMember = "AgentID";
我已将DataBindings添加到SelectedValue:
dropReagent.DataBindings.Add("SelectedValue", db.tblCustomers.First(x => x.CustomerID == ID), "ReagentID");
现在这里是SelectedValueChanged事件:
private void dropReagent_SelectedValueChanged(object sender, EventArgs e)
{
dropReagent.DataBindings[0].WriteValue();
db.SubmitChanges();
}
但是当我更改选定的值时,我会收到此错误:
其他信息:指数超出范围。必须是非负数且小于集合的大小。
哪里错了?我应该怎么做才能有一个干净的数据绑定来下拉选定的值?