Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a similar table like this. I created a sample Database, which needs to be binded with Treeview. The problem is it doesnot have ParentId. Instead in a step process it is made.
dId	step1	step2	step3	step4	step5	dname
1	0	0	0	0	0	drinks
2	1	0	0	0	0	cold
3	1	1	0	0	0	pepsi
4	1	1	1	0	0	zero
5	1	1	2	0	0	light
6	1	1	3	0	0	heavy
7	1	2	0	0	0	cola
8	1	2	1	0	0	zero
9	1	2	2	0	0	light
10	1	2	2	1	0	onelight
11	1	2	2	2	0	twolight
12	1	3	0	0	0	7Up
13	2	0	0	0	0	hot
14	2	1	0	0	0	coffee
15	2	1	1	0	0	black
16	2	1	2	0	0	Espresso
17	2	1	3	0	0	Latte
18	2	1	4	0	0	Cappucino
19	2	2	0	0	0	Tea
20	2	2	1	0	0	Ginger
21	2	2	2	0	0	Lemom
22	2	2	3	0	0	Mint
23	2	2	3	1	0	Peppermint
24	2	2	3	2	0	Normalmint
25	3	0	0	0	0	hotcold
26	3	1	0	0	0	water
27	3	2	0	0	0	lassi
28	3	2	1	0	0	Mango
29	3	2	2	0	0	plain


i want a treeview like this :-

https://photos.google.com/share/AF1QipMwvbOB7R4oRVBRUGeNZ7aOt2j4ZfiRU2DS_SZbiOZQaCaOyAs_A54bzYxzpFmrLA?key=WFBsR1FGN1lEa1lhMzBRZEZrdFNQLVRCeGI4ei1n

What I have tried:

I am new to WPF and treeview is so new concept. I couldn't where to start. I learned about Hierarchical data template. But I don't know how to work with this database. I couldn't find a proper solution similar like this. So only I am posting the question here.
Posted
Updated 6-Mar-19 9:22am
v3

1 solution

You have a "parent": it's "drinks"

Then you have "cold" (drinks).

Under "cold", you have "Pepsi" and then types of Pepsi.

etc.

Draw a picture.

Simple WPF TreeView Control Programmatically[^]
 
Share this answer
 
Comments
Priya Karthish 6-Mar-19 12:12pm    
I need to retrieve from database and store in the treeview. This is a sample database. I have almost 300 rows of data.
Graeme_Grant 6-Mar-19 16:10pm    
You have a Hierarchical structure in your data already. Why not create a new table that contains the parent id and item id and then write a SQL query to pull the data in the format that you want... Remember, we're not here to do your work for you, we're here to help give you guidance. ;)
Priya Karthish 6-Mar-19 16:40pm    
To be frank it has 1000 rows in my original database. Is it possible to create a table with parent ID?

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