Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 :)

  • Administrators
Posted

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?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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 :)

  • Administrators
Posted

In pseudo code you would want to do something like...

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...