Click here to Skip to main content
16,015,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this 4 table in SQL Server 2012
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

Note (some times The Departments has no employees & also must be appear in the treeview)

And I want to show my data in treeview according to Departments names such as that

DepName ------- first node SpecialName --- Second node EmpFullName --- Third node

I use Linq query to get my data and XAML like that:


C#
<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;


But my data doesn't appear correctly only first node appear. So my question is where is the wrong here. Thanks.
Posted
Updated 19-May-13 13:40pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900