K
Karl Rhodes
Hi all this may seem really easy to most of you, but Im just getting to
grips with 2005 and the new features.
I have a dataset from a database which has a ParentID, ChildID and
ObjectName fields.
I was under the impression I should be able to just cycle through the
rows in the dataset and add them (or insert them using the indexofkey
by the ParentID) to the TreeNodeCollection for the treeview. However,
when I go to fins the indexs for the third level objects or lower no
index is found and it all goes pear shaped.
If anyone has a very simple example of populating a treeview control
using vb.net from a dataset using the schema I have described, please
point me in the right direction or email it to me at karlrhodes at
hotmail dot com
Dim arrNodes() As TreeNode
Dim oNodes As TreeNodeCollection = myTreeView.Nodes
For Each oDRow In myDataSet.Tables("Hierarchy").Rows
strChildID = oDRow("Object_Id")
strObjectName = oDRow("ObjectName")
If Not IsDBNull(oDRow("Parent_Id")) Then strParentID =
oDRow("Parent_Id") Else strParentID = 0
arrNodes = oNodes.Find(strParentID, True)
numX = UBound(arrNodes)
If numX >= 0 Then
intIndex = arrNodes(numX).Index
Else
intIndex = -1
End If
If numX = 0 Then
oNodes.Add(strChildID, strObjectName)
Else
If oNodes.ContainsKey(strParentID) Then
oNodes(intIndex).Nodes.Add(strChildID, strObjectName)
End If
End If
numX = numX + 1
Next
Thanks
grips with 2005 and the new features.
I have a dataset from a database which has a ParentID, ChildID and
ObjectName fields.
I was under the impression I should be able to just cycle through the
rows in the dataset and add them (or insert them using the indexofkey
by the ParentID) to the TreeNodeCollection for the treeview. However,
when I go to fins the indexs for the third level objects or lower no
index is found and it all goes pear shaped.
If anyone has a very simple example of populating a treeview control
using vb.net from a dataset using the schema I have described, please
point me in the right direction or email it to me at karlrhodes at
hotmail dot com
Dim arrNodes() As TreeNode
Dim oNodes As TreeNodeCollection = myTreeView.Nodes
For Each oDRow In myDataSet.Tables("Hierarchy").Rows
strChildID = oDRow("Object_Id")
strObjectName = oDRow("ObjectName")
If Not IsDBNull(oDRow("Parent_Id")) Then strParentID =
oDRow("Parent_Id") Else strParentID = 0
arrNodes = oNodes.Find(strParentID, True)
numX = UBound(arrNodes)
If numX >= 0 Then
intIndex = arrNodes(numX).Index
Else
intIndex = -1
End If
If numX = 0 Then
oNodes.Add(strChildID, strObjectName)
Else
If oNodes.ContainsKey(strParentID) Then
oNodes(intIndex).Nodes.Add(strChildID, strObjectName)
End If
End If
numX = numX + 1
Next
Thanks