Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2010 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2010 Programmer's Reference by Rod Stephens; ISBN: 9780470499832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2010 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 5th, 2012, 12:42 PM
Authorized User
Points: 193, Level: 3
Points: 193, Level: 3 Points: 193, Level: 3 Points: 193, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Question Three Level TreeNodes

Hi Rod,

I haven't received a reply the last few times I've posted. If it is not too much trouble, am stumped again and would appreciate your valuable help. I am working with an application that involves an hierarchical list. I am able to generate one and two level lists but I am having trouble with three and possibly four levels. I have entered the code for level one, level two and level three node creations.

Level one Node creation takes the contents of TextBox1 and creates a Root level Node in TreeView1.

Level Two Node Creation take the contents of TextBox2 and creates a Root level Node under the root level node that is selected.

However, Level Three Node Creation acts differently. Although it takes the contents of TextBox3 and places it under the selected (second level) node. it causes the Second level Node to change to a Root level Node.

How can I add the third level Node without knocking both the second and third level nodes back down to Root and Second level nodes

Code:
Public Class CreateIndex

    'Create a Root Level Node
    Private Sub btnLevelOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLevelOne.Click

        Dim NewNodes As String
        NewNodes = TextBox1.Text
        TreeView1.Nodes.Add(NewNodes)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLevelTwo.Click

        'Create a Level Two Node
        Dim ChildNode As String
        ChildNode = TextBox2.Text

        Dim objNode As TreeNode
        objNode = TreeView1.SelectedNode()

        TreeView1.Nodes.Remove(TreeView1.SelectedNode)
        TreeView1.Nodes.Add(objNode)
        objNode.Nodes.Add(ChildNode)

        



    End Sub
    Private Sub btnLevelThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLevelThree.Click

        'Create a Level Three Node
        Dim GrandchildNode As String
        GrandchildNode = TextBox3.Text

        Dim objNode As TreeNode
        objNode = TreeView1.SelectedNode()

        Dim objNode2 As TreeNode
        objNode2 = TreeView1.SelectedNode()


        TreeView1.Nodes.Remove(TreeView1.SelectedNode)
        TreeView1.Nodes.Add(objNode2)
        objNode.Nodes.Add(GrandchildNode)

    End Sub
Reply With Quote
  #2 (permalink)  
Old March 5th, 2012, 03:03 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Sorry about not replying. I've been buried in work and the original message got moved out of my inbox so I just forgot about it. If I don't reply within 2 or 3 days, feel free to post a reminder.

Code:
        Dim objNode As TreeNode
        objNode = TreeView1.SelectedNode()

        TreeView1.Nodes.Remove(TreeView1.SelectedNode)
        TreeView1.Nodes.Add(objNode)
        objNode.Nodes.Add(ChildNode)
I think you probably don´t want to remove the selected node, just add the new node to its child list. Something like

Code:
        Dim objNode As TreeNode
        objNode = TreeView1.SelectedNode()
        objNode.Nodes.Add(ChildNode)
Let me know if that works.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The next level justinneng HTML Code Clinic 1 May 23rd, 2013 10:07 AM
TreeNodes Gary108 BOOK: Visual Basic 2010 Programmer's Reference 1 March 5th, 2012 03:28 PM
issue traversing from 3 level down to 3 level up in xml eruditionist XSLT 3 September 22nd, 2010 01:32 PM
expansion and collapse of treenodes in jsp page pavankumar_tatiraju Javascript 0 February 12th, 2007 02:56 AM
2-Level Menu mahulda ASP.NET 1.0 and 1.1 Basics 1 April 11th, 2004 09:29 PM



All times are GMT -4. The time now is 10:25 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.