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
For Each dr As DataRow In dt.Rows
Dim tnRoot As TreeNode = New TreeNode(dr.Item("parent")
tnRoot.Nodes.Add(dr.Item("
tnRoot.Nodes.Add(dr.Item("
tv.Nodes.Add(tnRoot)
Next
to
For Each dr As DataRow In dt.Rows
Dim tnRoot As TreeNode
If tv.Nodes.ContainsKey(dr.It
tnRoot = tv.Nodes(dr.Item("parent")
Else
tnRoot = New TreeNode(dr.Item("parent")
End If
tnRoot.Nodes.Add(dr.Item("
tnRoot.Nodes.Add(dr.Item("
tv.Nodes.Add(tnRoot)
Next