将SelectedValuePath分配给Comobox后,仍然会在分配时将SelectedValue置为null。 comboBox会填充数据,但是当id被分配给SelectedValue时,它总是返回null。
C#:
var fillDoctor = (from a in db.Persons
select new
{
id = a.id,
name = a.name + " " + a.middle_name + " " + a.last_name
});
_cmbDoctor.ItemsSource = fillDoctor;
_cmbDoctor.DisplayMemberPath = "name";//"first_name" + " " + "middle_name" + " " + "last_name";
_cmbDoctor.SelectedValuePath = "id";
_cmbDoctor.SelectedValue = 51;
MessageBox.Show(_cmbDoctor.SelectedValue.ToString());
答案 0 :(得分:0)
您确定您的身份证号码是51吗?如果没有这样的ID,则组合框无需指向