Solved

Adding children to a treeview after the main nodes are created

Posted on 2004-09-24
3
344 Views
Last Modified: 2010-04-23
Is there a way to add children to the main nodes after the main nodes are already in the treeview? For instance the treeview looks like this upon load:

1
2
3
4
5

On a button click, I want to add children to certain nodes:

1
2
  1
  2
3
4
  1
5

Is there a way?
0
Comment
Question by:originsone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
ID: 12144665
yep, like this

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       TreeView1.Nodes(1).Nodes.Add("1")
        TreeView1.Nodes(1).Nodes.Add("2")
        TreeView1.Nodes(3).Nodes.Add("1")
end sub
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12144676
Here are two different examples.  The first adds two children to the currently selected node.  The second add two children to the 5th node.

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        For i = 1 To 10
            TreeView1.Nodes.Add("Node" & i)
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim curNode As TreeNode = TreeView1.SelectedNode ' get currently selected node
        If Not (curNode Is Nothing) Then
            Dim i As Integer

            For i = 1 To 2
                curNode.Nodes.Add("Child" & i)
            Next i
            curNode.Expand()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim curnode As TreeNode = TreeView1.Nodes(4) ' get 5th node in root
        curnode.Nodes.Add("Child1")
        curnode.Nodes.Add("Child2")
    End Sub

End Class
0
 

Author Comment

by:originsone
ID: 12144714
Simplicity. Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question