recursive loop

usvpn

Freshman
Joined
Apr 19, 2010
Messages
45
Hi everyone, I am an intermediate programmer with a basic understanding of VB.NET, however, I am having a problem with a special loop named "recursive".
I didn't learn this and now am having a problem here:

To select the 3rd subitem/node inside a control named "CrumbBar", I have to:

CrumbBar1.SelectedItem = CrumbBar1.Items(0).SubItems(0)
CrumbBar1.SelectedItem = CrumbBar1.Items(0).SubItems(0).SubItems(1)
CrumbBar1.SelectedItem = CrumbBar1.Items(0).SubItems(0).SubItems(1).SubItems(2)

And go through all items, but I need to do this in a LOOP.
And I don't know how many nodes I will have to go inside.
So I wanna know how can I loop the above code?
Someone told me this is a simple recursive loop programming task.
Not easy to me, how should be that? Any help, please :)
 
A recursive function is one that will call itself and it can be very useful in solving certain kinds of problems.

In your case will you be wanting to return all sub items of all sub items or will there be a way of identifying the one you are after?
 
Hi,
Nothing is returned, I am setting "SelectedItem" property, so it will just set the selected item for each node and will go forward and when finished, it's done :)
 
In pseudo code you would want to do something like...
Code:
Sub SetSelectedItem(subItem as Item)
    If subItem has children then
         For Each Child call SetSelectedItem(child node)
   End If
Set subItem as selected
End Sub
As long as you never have circular references you should be fine, if there are circular references you would need a way to track which nodes have already been visited.
 
Back
Top