我在 SQL Server 2012 中有这 4 个表
DepartmentsTbl
==============
DepID ------- DepName
1 ------- Human Resources
2 ------- Financial Management
SpecialTbls:
============
SpclID ------- SpclName
1 ------- Manager
2 ------- Secretary
3 ------- Data entry
EmployeesTbl:
============
EmpID ------- EmpName
1 ------- Jack
2 ------- Mark
3 ------- Sara
JobDescriptionTbls:
===================
JDID ------- EmpID ------- DepID ------- SpclID
1 ------- 1 ------- 1 ------- 1
2 ------- 2 ------- 1 ------- 2
3 ------- 2 ------- 1 ------- 3
注意 (有时部门没有员工,也必须出现在树形视图中)
我想根据部门名称在树视图中显示我的数据,例如
DepName ------- first node
SpecialName --- Second node
EmpFullName --- Third node
我使用 Linq 查询来获取我的数据和 XAML,如下所示:
XAML:
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=DepartmentsTbls}">
<TextBlock Text="{Binding Path=DepName}"
Foreground="#FFF59E13" />
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=SpecialName}"
Foreground="White" />
</DataTemplate>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=EmpFullName}"
Foreground="White" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</TreeView.ItemTemplate>
林克:
var Employees = (from spcl in menof.SpecailTbls
join deps in menof.DepartmentsTbls
on spcl.SoecialID equals deps.DepID
//from deps in menof.DepartmentsTbls
join eJD in menof.EmpJobDescriptionTbls
on deps.DepID equals eJD.DepID
join emps in menof.EmployeesTbles
on eJD.EmpID equals emps.EmpID
select new { spcl.SpecialName,deps.DepName,emps.EmpFullName }).ToList();
tvEmpsName.ItemsSource = Employees;
但是我的数据没有正确显示,只有第一个节点出现。所以我的问题是这里哪里错了。谢谢。