Dynamically Created TreeView not expanding/collapsing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    Dynamically Created TreeView not expanding/collapsing

    Hi-

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

    For Each drPA As DataRow In dsMasterList.Ta bles(0).Rows
    iRoot = iRoot + 1
    nRootNode = New TreeNode(drPA(0 ), iRoot, "", "", "")
    nRootNode.Selec tAction = TreeNodeSelectA ction.Expand
    tvMasterList.No des.Add(nRootNo de)
    For Each drSubject As DataRow In
    dsMasterList.Ta bles(1).Rows
    If (drSubject(1) = nRootNode.Text) Then
    iSub = iSub + 1
    nSubNode = New TreeNode(drSubj ect(1), iSub, "",
    "", "")
    nRootNode.Child Nodes.Add(nSubN ode)
    For Each drTopic As DataRow In
    dsMasterList.Ta bles(2).Rows
    If (drTopic(1) = nSubNode.Text) Then
    iTopic = iTopic + 1
    nTopicNode = New TreeNode(drTopi c(1),
    iTopic, "", "", "")
    nSubNode.ChildN odes.Add(nTopic Node)
    End If
    Next
    'nSubNode.Expan d()
    End If
    Next
    'tvMasterList.N odes.Add(nRootN ode)
    'nRootNode.Expa nd()
    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.
  • Chris

    #2
    Re: Dynamically Created TreeView not expanding/collapsing

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

    On Feb 24, 4:46 pm, Chris <coz1...@gmail. comwrote:
    Hi-
    >
    I'm running this database query where the resultswillbe used to
    populate mytreeview.
    >
    For Each drPA As DataRow In dsMasterList.Ta bles(0).Rows
                iRoot = iRoot + 1
                nRootNode = New TreeNode(drPA(0 ), iRoot, "", "","")
                nRootNode.Selec tAction = TreeNodeSelectA ction.Expand
                tvMasterList.No des.Add(nRootNo de)
                For Each drSubject As DataRow In
    dsMasterList.Ta bles(1).Rows
                    If (drSubject(1) = nRootNode.Text) Then
                        iSub = iSub + 1
                        nSubNode = New TreeNode(drSubj ect(1), iSub, "",
    "", "")
                        nRootNode.Child Nodes.Add(nSubN ode)
                        For Each drTopic As DataRow In
    dsMasterList.Ta bles(2).Rows
                            If (drTopic(1) = nSubNode.Text) Then
                                iTopic = iTopic + 1
                                nTopicNode = NewTreeNode(drT opic(1),
    iTopic, "", "", "")
                                nSubNode.ChildN odes.Add(nTopic Node)
                            End If
                        Next
                        'nSubNode.Expan d()
                    End If
                Next
                'tvMasterList.N odes.Add(nRootN ode)
                'nRootNode.Expa nd()
            Next
    >
    If I uncomment theexpandfuncti ons, I can see that my code works
    nicely, and thetreeviewis populated correctly.  But it won'texpand
    or collapse!  When I try it I get the following error in the IE
    'debugger':
    >
    "Childnodes .0 is null ornotan object"
    >
    I'm really lost here, any helpwillbe greatly appreciated.

    Comment

    Working...