We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 124,525 times

Contents

Downloads

Related Categories

TreeView Control - Removing Nodes

Removing Nodes

To remove an node, you either need to know its Index or its unique key (if you gave it one). Then you use the following syntax:

TreeView1.Nodes.Remove IndexOrKey

The following example first removes a node which key is "root", and then removes a node which key is 12.

TreeView1.Nodes.Remove "root"
TreeView1.Nodes.Remove 12

Note that if a node has sub items when it is removed, all its sub items are removed too.

If you want to remove all the nodes in the TreeView, you can use the Clear method:

TreeView1.Nodes.Clear

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • treeview

    Posted by jmhshep on 03 Mar 2005

    I tried your treeview example and when I try to add and image it is telling me that I need to initilaize the image first. Can you tell me what that means and how to fix it

  • treeview

    Posted by directorz on 28 May 2004

    I tried this and recieved the following: Compile error: variable not defined..."TreeView" is highlited...anyone have any ideas?

  • Good & Thanks

    Posted by gabar on 14 May 2004

    Very Good, You have helped me.

    gabriel medina
    gxsoft@hotmail.com

  • Good

    Posted by behmagvb on 11 Aug 2003

    Good Example isn't it?
    http://www.pldental.com

  • ??? Got Problems with that

    Posted by LittleMik on 24 Jun 2003

    Hi,

    Found this very good tutorial because its nearly exact the problem i have with my TreeView,...
    ...but unfortunatly, i can't get it to work...

    Set the same settings like in the tutorial, but...