On 2008-07-11, JR <xx****@xx.xxwrote:
Hi,
I need a routine/finction that finds a text, starting at the selected node,
where a given text is in.
say i have some nodes with 1 'sonday' and another with 'son' and I look for
'so' it will first find 'sonday' and the next time 'son'. ones it have found
everything with the look parameter it restart at the top.
Jan
Hmmm... Not exactly sure what your asking - but searching a treeview is a
simple recursive type algorithm. What I'm not sure on is if you want one node
at a time returned or all nodes? I'll go with all nodes :) Here is a quick
off the top bit of aircode that should get you started:
Function SearchTree (ByVal root As TreeNode, ByVal text As String) As List (Of TreeNode)
Dim nodes As New List (Of TreeNode)()
' case insensitive
If root.Text.ToUpper().Contains (text.ToUpper()) Then
nodes.Add(root)
End If
For Each node As TreeNode In root.Nodes
Dim subNodes As List(Of TreeNode) = SearchTree(node, text)
If (subNodes.Count 0) Then
nodes.AddRange (subNodes)
End If
Next
Return nodes
End Function
Called like:
Dim foundNodes As List(Of TreeNodes) = SearchTree (TreeView1.SelectedNode, text)
Of course, you'd want to check to make sure there was a selected node first :)
--
Tom Shelton