Hello everyone,
I've reached a dead end right now trying to get my TreeNodes to load dynamically.
I start by adding a base node as a starting point.
Dim trnBase As New TreeNode
trnBase.Text = "Search"
tvw_Search.Nodes.Add(trnBase)
At this point there are no problems. trnBase has been added to tvw_Search. And the indexOf property of trnBase has been set to 0 (which will be used later in this subroutine).
Later on in this same subroutine I itterate through a DataTable containing my Nodes. Each itteration I check the ParentNodeIndex value. I then use that to get the ParentNode from the node collection of tvw_Search. Then I add the record as a node to the ParentNode.
Dim intParentNodeIndex As Integer = drRow(4)
Dim trnChildNode As New TreeNode
trnChildNode.Text = drRow(7)
Dim trnParentNode As New TreeNode
trnParentNode = tvw_Search.Nodes.Item(intParentNodeIndex)
trnParentNode.Nodes.Add(trnChildNode)
Now this is where I have trouble. The problem lies in the IndexOf property of the child nodes. When I added trnBase (the first set of code) trnBase gets assigned "IndexOf = 0". However, the nodes that are added via the Database (the second set of code) are not assigned an IndexOf value.
In other words, in my DataTable the first 5 records have "ParentIndexOf = 0". They are added to trnBase (indexOf = 0) no problem because trnBase was assigned an Index value of 0. The problem begins when I try to add nodes to these 5 new nodes. These 5 new nodes were never assigned an IndexOf value. Not only that, they aren't recognized in the tvw_Search nodes collection. When I do a "For each node in" tvw_Search, it only loops once for Node "trnBase", even though the first 5 records were added to "trnBase".
The only difference that could make any difference in my code is the last line in each set:
tvw_Search.Nodes.Add()
trnBase.Nodes.Add()
Is there something different I have to do as far as adding nodes to nodes to that of nodes to Trees?
Thank you for any help.
Alec