Question How to add a treeview node in x level

xeneize16

New member
Joined
Mar 28, 2013
Messages
1
Programming Experience
3-5
Hello. Please, sorry for my bad English. I need to know how can i to add a treeview node in x level. When my windows Form load, the project should fill a treeview using databases data. I need to make this job node to node and i don't know how... For example, i need to add a node in the fourth leven like shows the picture:

Captura.JPG

would greatly appreciate your help because i am braked in it.

Bye
 
Hi,

The way to create a TreeView is to ensure that you create a reference to the Parent Node that you want to add children to.

To demonstrate, have a look at this quick example:-

VB.NET:
Public Class Form1
 
  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    'Declare the Parent node of the Treeview
    Dim ParentNode As New TreeNode("ParentNode")
 
    'Add the Parent Node to the Treeview
    TreeView1.Nodes.Add(ParentNode)
 
    'Now use the Parent Node Object to add a defined Child Node
    Dim ChildNode As TreeNode = ParentNode.Nodes.Add("ChildNode")
 
    'Now use the ChildNode Object (which is now another Parent to its own children) to add Another defined Child Node object
    Dim AnotherChildNode As TreeNode = ChildNode.Nodes.Add("AnotherChildNode")
  End Sub
End Class

Hope that helps.

Cheers,

Ian
 
Back
Top