Looping Through All Nodes In A VB.NET Tree View And Highlighting Them.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Michael The Red (michaelthered_at_hotmail.com)
Date: 07/06/04


Date: 5 Jul 2004 21:31:10 -0700

I am attempting to loop through all the nodes in a tree view and
highlight them as the loop is active. All nodes would include to
children nodes of parent nodes and so on.

I have a function in my application that builds a tree view. It
populates the tree view with parent nodes. The parent nodes are the
drives on my pc. When the user selects the node, I have a function
that takes the tag of the node and passes it to the Directory method.
A node is then created under the selected node with folder names.

I now have a tree view with parent and children nodes. Now, I would
like to loop through all the nodes in the tree view as it is now. For
example…the Root Parent nodes are drives A, C, D, E, and F. When the
user selects F, then children nodes are added…like…Movie Folder, Doc
Folder, File Folder….whatever folders that are under F. I would like
to loop through all the nodes and highlight them as the loop goes
along.

I figured I could get a node count in the beginning and simply
interate through the node index. In my example, the node count was
something like 15. so I figured I could just do something like this…

Dim nodeCount As Intger = TreeView.GetNodeCount(True)
Dim inc As Integer = 0
Dim nodeTag As String

Do While Not(inc > nodeCount)
        nodeTag = TreeView.Nodes.Item(inc).Tag
        ‘HIGHLIGHT THIS NODE AND DO SOMETHING WITH NODE

inc = inc + 1
Loop

The problem I am seeing is that the node count is 15, because I added
nodes to the tree from a nodes selection event, but when I go to index
6, I get a message like "Index is out of range." I figured it should
be in range because the nodes exist.

Do I have to do something special to add the nodes to the nodes
collection? Aren't the nodes automatically added to the node
collections when they are created? Why would child nodes be out of
range?

I don't know how I can simply loop through all the nodes, could
someone please, please, please help me out with this?

Thank you all.



Relevant Pages

  • Re: Update command
    ... I always talk about and it has many BWidgets inside it. ... Only part is the node insertion of the tree using the data from ... in a loop. ... parent nodes at startup; create other nodes on demand as your users open ...
    (comp.lang.tcl)
  • Re: Is There a Java Class for this Kind of Data Structure?
    ... They can be affected by uncles/aunts, but NOT by siblings. ... I was looking into a tree because I thought that would be the easiest way to ... who in turn notify their dependents and so on. ... Right now I'm experimenting with a loop that I wouldn't actually label as ...
    (comp.lang.java.programmer)
  • Re: Need some light on using Ada or not
    ... As this is my first experiment with tasking, comments are welcome (and I'd be ... there said that we couldn't use arrays as binary-trees. ... -- If it is a large enough tree, ... For Index in Internal_Nodes Loop ...
    (comp.lang.ada)
  • Re: The Collatz discrete primes!
    ... doubling outside the loop. ... longer on the counter example tree than on the regular tree. ... example being pure or impure but my thought is that the ... smallest odd integer in the counter example path would have ...
    (sci.math)
  • Re: The Collatz discrete primes!
    ... doubling outside the loop. ... longer on the counter example tree than on the regular tree. ... example being pure or impure but my thought is that the ... smallest odd integer in the counter example path would have ...
    (sci.math)