usvpn Posted April 19, 2010 Posted April 19, 2010 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 :) Quote
Administrators PlausiblyDamp Posted April 19, 2010 Administrators Posted April 19, 2010 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
usvpn Posted April 19, 2010 Author Posted April 19, 2010 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 :) Quote
Administrators PlausiblyDamp Posted April 19, 2010 Administrators Posted April 19, 2010 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Administrators PlausiblyDamp Posted April 21, 2010 Administrators Posted April 21, 2010 Any chance you can just post a simplified version of the problem you are having here? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.