Results 1 to 2 of 2

Thread: Creating a Child node in a treeview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    20

    Creating a Child node in a treeview

    The folowing code loops round looking for NodeKey to match the NextParent. Nodekey is a Key which I have setup for the Nodes Class

    When it matches the key I wish to find the index of that key and then set the selected node to that index and create a new child underneath.

    Unfortuently this code does not seem to work. Does anybody have any ideas.

    'Loop Round tree View
    If (cNode.NodeKey = nextParent) Then
    sString = nextElement & " " & nextDesc
    iRecord = cNode.Index

    TreeView1.SelectedNode = TreeView1.Nodes(iRecord)
    Nextmode = TreeView1.SelectedNode

    NextMode.Nodes.Add(New HalcrowTreeNode(sString, nextElement))

    End If

    Thanks in Advance

    Daniel

  2. #2
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64
    am not sure if it works because i don't know how your custom node looks like but i think it should be
    VB Code:
    1. If (cNode.NodeKey = nextParent) Then
    2. sString = nextElement & " " & nextDesc
    3. TreeView1.SelectedNode = cNode
    4. 'rest of the code
    or, if your class alows it
    VB Code:
    1. If (cNode.NodeKey = nextParent) Then
    2. sString = nextElement & " " & nextDesc
    3. TreeView1.SelectedNode = CType(cNode,Treenode)
    4. ''rest of the code
    if my ideea of nodeindex is right then index reffers only to the first level of childnodes of the referred node

    something like this
    ( (n) are indexes )
    VB Code:
    1. '  [+]root(0)
    2. '       |    
    3. '       |------child1(0)
    4. '       |
    5. '       |---[+]child2(1)
    6. '       |        |
    7. '       |        |------child3(0)
    8. '       |        |
    9. '       |        '------child4(1)
    10. '       |
    11. '       '------child5(2)
    ie. to reffer child4 you would use mytree.nodes(0).nodes(1).nodes(1)

    by the way if one of the code above works for you i'd like to know how your custom treeview class looks like because i never really managed to inherit the treeview and treenode and add custom properties to them.
    i found a workthrough on microsoft page wich doesn't work, or it's something i'm missing
    it's located here
    http://support.microsoft.com/default.aspx?scid=KB;EN-US;311318
    Last edited by mindloop; Mar 29th, 2004 at 07:32 AM.
    ehmm...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width