[英]Getting data from comboBox and use it to get data in onother combobox
I have a two comboboxes in my app. 我的应用程序中有两个组合框。 One of them, cmb1
, is binding with a table called Branches, and the other one, cmb2
, is binding with another table called teachers
. 其中一个, cmb1
,与一个名为Branches的表绑定,另一个, cmb2
,与另一个名为teachers
表绑定。 The relation between them is many to many in a table called subjectteachers
. 在称为subjectteachers
的表格中,它们之间的关系是多对多的。 I need to know how to take the Id of selected cmb1
and search in table subjectteachers
with that id and get the name from table teachers
to put it in cmb2
我需要知道如何获取所选cmb1
的Id并在具有该id的表subjectteachers
搜索并从表teachers
获取名称以将其放入cmb2
CollegeContext cd = new CollegeContext();
Branch SectionCB = CBTypeOfSection.SelectedItem as Branch;
var query = from b in cd.Branches
where (from st in cd.SubjectTeachers
where (st.IdBranch == SectionCB.Id &&
(from t in cd.Teachers
where
(t.Id == st.IdTeacher)
select t.Name) select st))
select b;
TeachersComboBox.ItemsSource = query.ToList();
this is called lambda its really helpfull hope you like it. 这被称为lambda,它真的很有帮助,希望你喜欢它。
var query = cd.Subjectteachers.Where(x=>x.IdBranch==SectionCB.Id).Select(x=>x.Teacher);
TeachersComboBox.DisplayMemberPath = "idwork";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.