Solved

Adding children to a treeview after the main nodes are created

Posted on 2004-09-24
3
343 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 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