By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,629 Members | 1,523 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,629 IT Pros & Developers. It's quick & easy.

Treeview and find text in node

P: n/a
JR
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

Jul 11 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 11 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.