Dynamically Created TreeView not expanding/collapsing

C

Chris

Hi-

I'm running this database query where the results will be used to
populate my treeview.

For Each drPA As DataRow In dsMasterList.Tables(0).Rows
iRoot = iRoot + 1
nRootNode = New TreeNode(drPA(0), iRoot, "", "", "")
nRootNode.SelectAction = TreeNodeSelectAction.Expand
tvMasterList.Nodes.Add(nRootNode)
For Each drSubject As DataRow In
dsMasterList.Tables(1).Rows
If (drSubject(1) = nRootNode.Text) Then
iSub = iSub + 1
nSubNode = New TreeNode(drSubject(1), iSub, "",
"", "")
nRootNode.ChildNodes.Add(nSubNode)
For Each drTopic As DataRow In
dsMasterList.Tables(2).Rows
If (drTopic(1) = nSubNode.Text) Then
iTopic = iTopic + 1
nTopicNode = New TreeNode(drTopic(1),
iTopic, "", "", "")
nSubNode.ChildNodes.Add(nTopicNode)
End If
Next
'nSubNode.Expand()
End If
Next
'tvMasterList.Nodes.Add(nRootNode)
'nRootNode.Expand()
Next

If I uncomment the expand functions, I can see that my code works
nicely, and the treeview is populated correctly. But it won't expand
or collapse! When I try it I get the following error in the IE
'debugger':

"Childnodes.0 is null or not an object"

I'm really lost here, any help will be greatly appreciated.
 
C

Chris

This can be disregarded. I put the code inside of the form_load sub,
and it works perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top