我有两个具有CourseID和Name的表课程,以及具有SectionID,CourseID,价格,时间的部分。我有以下代码,我不知道如何使用组合框的desiplaymember和displayvalue。 提前谢谢
var fillcmb=(from crs in re.Sections
from r in re.Courses
where crs.CourseID == r.CourseID
select r.Name.ToString()).ToList();
coursecmb.DataSource = fillcmb;
coursecmb.DisplayMember = "Name";
coursecmb.ValueMember = "CourseID";
答案 0 :(得分:1)
您没有从LINQ查询中选择适当的属性:
var fillcmb=(from crs in re.Sections
from r in re.Courses
where crs.CourseID == r.CourseID
select new { Name = r.Name.ToString(), CourseID = crs.CourseID})
.ToList();