How to populate a TreeView control from database
Posted on 2011-10-31
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'".