troubleshooting Question

Load Treeview using Dataset

Avatar of transstates
transstatesFlag for United States of America asked on
Visual Basic.NET
5 Comments1 Solution243 ViewsLast Modified:
Good Morning All,

What am I doing wrong?  What I have is a dataset that has three fields (parent, pn, sn) and I want these to display in a treeview as follows:

        Parent
            pn
                 sn
                 sn
             pn
                  sn
                  sn

and so on.  What I get when I run my code is the parent multiple times.  I want 1 parent with ? of children with ? of sub children.  Heres a piece of code I'm using:
 
       tv.nodes.clear
       tv.BeginUpdate()
        Dim dt As DataTable = dsData.Tables("table1")
        For Each dr As DataRow In dt.Rows
           
            Dim tnRoot As TreeNode = New TreeNode(dr.Item("parent").ToString)
            tnRoot.Nodes.Add(dr.Item("pn").ToString)
            tnRoot.Nodes.Add(dr.Item("sn").ToString)
            tv.Nodes.Add(tnRoot)

        Next
        tv.EndUpdate()

This displays:

Parent
   -->pn
   -->sn(this is the subchild)

Parent (same as above)
   -->pn (same as above)
   -->sn (different)

Hope this makes sense?!?!

Thanks in advance...

jim
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros