Adding nodes to a treeview control

How do I programatically add nodes to a treeview control
I found some code from microsoft but its for .net 1.1.  
Private Sub bindRegions()
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("PCI").ConnectionString
        Dim conn As SqlConnection
        conn = New SqlConnection(connectionString)
        Dim DSRegions As DataSet
        Dim DARegions As New SqlClient.SqlDataAdapter("SELECT RegionID, RegionName FROM Region", conn)
        Dim DACountries As New SqlClient.SqlDataAdapter("SELECT CountryID, CountryName FROM Country", conn)
        Dim DASubRegions As New SqlClient.SqlDataAdapter("Select SubRegionID, SubRegionID from SubRegion", conn)
 
        DSRegions = New DataSet()
        conn.Open()
        DARegions.Fill(DSRegions, "dtRegions")
        DACountries.Fill(DSRegions, "dtCountries")
        DASubRegions.Fill(DSRegions, "dtSubRegions")
        'Close the connection to the data store; free up the resources
        conn.Close()
 
        'Create a data relation object to facilitate the relationship between the Customers and Orders data tables.
        DSRegions.Relations.Add("RegionToCountry", DSRegions.Tables("dtRegions").Columns("RegionID"), DSRegions.Tables("dtCountries").Columns("RegionID"))
        DSRegions.Relations.Add("CountryToSubRegion", DSRegions.Tables("dtCountries").Columns("CountryID"), DSRegions.Tables("dtSubRegions").Columns("CountryID"))
        '''''''''''''''''''''''
        TreeRegions.Nodes.Clear()
        Dim i, n As Integer
        Dim parentrow As DataRow
        Dim ParentTable As DataTable
        ParentTable = DSRegions.Tables("dtRegions")
 
        For Each parentrow In ParentTable.Rows
            Dim parentnode As TreeNode
            parentnode = New TreeNode(parentrow.Item(0))
            TreeRegions.Nodes.Add(parentnode)
            ''''populate child'''''
            '''''''''''''''''''''''
            Dim childrow As DataRow
            Dim childnode As TreeNode
            childnode = New TreeNode()
            For Each childrow In parentrow.GetChildRows("RegionToCountry")
                childnode = parentnode.ChildNodes.Add( = (childrow(0) & " " & childrow(1) & " " & childrow(2))
                childnode.Value = childrow("OrderID")
                ''''populate child2''''
                ''''''''''''''''''''''''''
                Dim childrow2 As DataRow
                Dim childnode2 As TreeNode
                childnode2 = New TreeNode()
                For Each childrow2 In childrow.GetChildRows("OrdToDet")
                    childnode2 = childnode.ChildNodes.Add.Add(childrow2(0))
 
                Next childrow2
                ''''''''''''''''''''''''
 
            Next childrow
            '''''''''''''''
        Next parentrow
 
    End Sub

Open in new window

monica73174Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shanmuga SundaramDirector of Software EngineeringCommented:
Though I am not much experienced in ASP.Net, please check whether this helps. Ignore if this is not you need

http://harriyott.com/2007/03/adding-dynamic-nodes-to-aspnet-site.aspx
http://www.eggheadcafe.com/articles/20011013.asp
0
monica73174Author Commented:
thank you for your help but unfortunately that wasnt what I was looking for.  I actually figured it out.

This is what I did to make it work.....

Dim parentrow As DataRow
        Dim ParentTable As DataTable
        ParentTable = DSRegions.Tables("dtRegions")
        TreeRegions.ImageSet = TreeViewImageSet.Simple
        'TreeRegions.
        For Each parentrow In ParentTable.Rows
            Dim parentnode As TreeNode
            parentnode = New TreeNode(parentrow.Item("RegionName"), parentrow.Item("RegionID"))
            parentnode.ShowCheckBox = True
            parentnode.NavigateUrl = ""
            TreeRegions.Nodes.Add(parentnode)

            ''''populate child'''''
            '''''''''''''''''''''''
            Dim childrow As DataRow
            Dim childnode As TreeNode
            childnode = New TreeNode()
            For Each childrow In parentrow.GetChildRows("RegionToCountry")
                childnode = New TreeNode(childrow.Item("CountryName"), childrow.Item("CountryID"))
                parentnode.ChildNodes.Add(childnode)
                childnode.NavigateUrl = ""
                ''''populate child2''''
                ''''''''''''''''''''''''''
                Dim childrow2 As DataRow
                Dim childnode2 As TreeNode
                childnode2 = New TreeNode()
                For Each childrow2 In childrow.GetChildRows("CountryToSubRegion")
                    childnode2 = New TreeNode(childrow2.Item("SubRegionName"), childrow2.Item("SubRegionID"))
                    childnode.ChildNodes.Add(childnode2)
                    childnode2.ShowCheckBox = True
                    childnode2.NavigateUrl = ""
                Next childrow2
                ''''''''''''''''''''''''

            Next childrow
            ''''''''''''''''
        Next parentrow
0
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.