Windows Develop Bookmark and Share   
 index > Windows Forms General > Treeview Tutorial
 

Treeview Tutorial

Does anyone know or a REAL tutorial on Treeview. Not loading ado, xml, directories, etc. I mean one that explains the properties of the Treeview control. The above is about all I can find on the internet.

What I am trying to do is add a node to the treeview in a predetermined location. I then want to add two sub-nodes to the one just entered.

Dim oNode As New TreeNode

oNode.Name = "Level1"

TreeView1.Nodes.Add(oNode)

TreeView1.SelectedNode.Name = oNode.Name ==> Getting error here

TreeView1.Nodes.Add("Level1a")

TreeView1.Nodes.Add("level1b")

oNode = Nothing

The error is "NullReferencException was unhandeled." and "Object reference not set to an instance of an object."

Any tutorial on this subject would be greatly appreciated.

WayneSpangler  Wednesday, June 08, 2005 4:19 PM
wayne your close... The treeview is a pain in the but I can say that, but to do what you want try to mess with the following code:



private sub createlevel1()
{
    Dim node as New TreeviewNode
    node.text = "level 1"
    Treeview1.Nodes.Add(node)
}

private sub createlevel2()
{
    Dim node as new TreeviewNode
    node.text = "Level 2"
    Treeview1.SelectectedNode.Nodes.Add(node)
}

 


Now what this will do is it will create a Level 1 node and then when you select that node and run the other method it will create a level 2 node under that. I hope this gives you some idea on how to use this control.
wacko  Wednesday, June 08, 2005 11:54 PM
wayne your close... The treeview is a pain in the but I can say that, but to do what you want try to mess with the following code:



private sub createlevel1()
{
    Dim node as New TreeviewNode
    node.text = "level 1"
    Treeview1.Nodes.Add(node)
}

private sub createlevel2()
{
    Dim node as new TreeviewNode
    node.text = "Level 2"
    Treeview1.SelectectedNode.Nodes.Add(node)
}

 


Now what this will do is it will create a Level 1 node and then when you select that node and run the other method it will create a level 2 node under that. I hope this gives you some idea on how to use this control.
wacko  Wednesday, June 08, 2005 11:54 PM
Thanks wacko, I appreciate it.
WayneSpangler  Thursday, June 09, 2005 12:18 AM

You can use google to search for other answers

Custom Search

More Threads

• Custom controls...how to get them to appear in toolbox
• how can i make a form visible based on a condition ?
• Control.DoubleBuffered should NOT be used?
• How to get design time support for custom collection ?
• BackgroundWorker with strange behaviour
• Loading Word Documents onto WebBrowser Control
• BitBlt in Visual Basic 2005
• Form Layouts...
• NUnit and Team System
• Programatically scroll the C# browser window