| re: Newb needs a little help
You,
In addition to Marina,
You can use the for each loop in this kind of routines.
However set it in a do until loop and exit when you have done an addition or
whatever. By instance this
\\\
Do until ("ready state is reached")
for each in collection
if condition then
'do what you have to do
exit for
end sub
next
loop
///
This can help you in a lot of cases, however do not do this when you are
sure that it will be with a lot of processing while a control is involved.
It is almost the same as a classic arraysort.
I hope this helps?
Cor
"you" <you@me.com> schreef in bericht
news:MPG.1bf98d7f7e058a31989680@news.microsoft.com ...[color=blue]
> Ok, I hope that I can 'splain this right. I am very new so bear with me.
>
> I have a treeview with its main node being a user selected folder. In
> this treeview you can only see subfolders and two specific file types.
> What I am trying to do next is to remove any subfolders from the tree
> that bo not have any of the two file types. This is done to somewhat
> unclutter the tree.
>
> Here is my code so far to clear the folders out. It is called with the
> topmost node as the inputnode to start with.
>
> Private Sub RemoveUselessFolders(inputnode as TreeNode)
> Try
> Dim node As TreeNode
> For Each node In inputnode.Nodes
> If node.ImageIndex < 2 Then 'it is a folder
> If node.Nodes.Count = 0 Then 'it has no subfolders-can remove
> node.Remove
> Else
> RemoveUselessFolders(node)
> End If
> End If
> Next
> Catch ex As system.NullReferenceException
> End Try
> End Sub
>
>
> This seems to throw NullReferenceException's and maybe deletes a folder
> and maybe not. I just do not understand why this does not work. I do not
> have VS, so I can not step through it and see what is (or isn't)
> happening. Anyone have a clue?
>
> If you need more info please let me know.
>
> Thanks,
> Jason[/color] |