views:

141

answers:

2

alt text

In Service Category table, ParentCategoryId is the ServiceCategoryId and that is the parent category, there can be nth level hierarchy of my categories, so I need to present this using Tree View Control.

How can I do this?

Thanks

A: 

You could use Hierarchical DataTemplate

HTH

Avatar
A: 

this link is the best answer to your choice

http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx

After seeing your class model

You can do something like this.

1- Determine Ultmate Root node which can be identified using following SQL statement

Select * from ServiceCategory where ServiceCategoryId = ParentCategoryId this will work if you are maintainng a row where values of the column ServiceCategoryId, ParentCategoryId are same.

But if the above select statement does not give you a result than you can try this below statement

Select * from ServiceCategory where ParentCategoryId = null if you are maintaining root node in this way.

either of the above statements should give you the root node of the tree

but if still not giving the root node that means you are storing data in some otherway.

2- Once you got the root node , you can use On-Demand loading of the child nodes.

Which can be done using adding a dummy node to the root node, it will give you the '+' sign against your root node and when you click to expend than you can query and get the Child nodes which is under the parent node.

saurabh