How to populate a TreeView control from database

I have a VS2010 C# Windows application, and I want to add a TreeView control to the form. I want to populate the TreeView control with data from tables within my SQL Server 2008 database.For example, my TreeView will have three nodes: Projects, Deliverables, and Times. Under each of these nodes, I want to pull data from the database, and add the data to each node. For Projects, the data will be pulled from "SELECT * FROM dbo.Projects", for Deliverables, the data will be pulled from "SELECT * FROM dbo.Tasks", and for Times, the data will be pulled from "SELECT * FROM dbo.WeekEndingDates". How would I go about doing? Another question I have is: once these nodes are populated, is there a way to change them upon user selection? For example, if a user selects "Project 1" under the Projects node, can the Deliverables node be repopulated with all the data from the database that is associated with "Project 1"? Example: User selects "Project 1" from Projects node, and then the Deliverables node is populated with "SELECT * FROM dbo.Tasks WHERE Project = 'Project 1'".
jjliu4492Asked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
If you don't know about SQL Server Common Table Expressions (CTEs), for hierarchical data, take a look:

Recursive Queries Using Common Table Expressions
http://msdn.microsoft.com/en-us/library/ms186243.aspx

You can get all the data in an ordered list, and build the tree from the table.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.