|
-
Nov 12th, 2007, 05:56 AM
#1
Thread Starter
PowerPoster
Search in treeview
I am trying to create a "filter" type treeview search where, when you start typing in a textbox, it will go to that treenode.
so if I had:
f
fi
fish
fishe
fisher
and start to type "f", it would go to the first instance found of nodes beginning with "f", and if I typed in the next letter, it would highlight/go to that instance...and so on
I know there is a Find method in the TreeView Nodes collection but that is not quite working for me as you need to give it the full name of the treeview node name.
Any ideas?
-
Nov 12th, 2007, 06:04 PM
#2
Re: Search in treeview
Here's a refinement of the code I posted in your other thread:
CSharp Code:
private TreeNode FindNode(TreeNodeCollection nodes, string text)
{
TreeNode match = null;
foreach (TreeNode node in nodes)
{
if (node.Text.StartsWith(text))
{
// The current node is the first match.
match = node;
break;
}
else if ((match = this.FindNode(node.Nodes, text)) != null)
{
// A descendant of the current node is the first match.
break;
}
}
return match;
}
Just note that, while I wrote that code in an IDE I never actually tested it, so I can't guarantee it 100%. I'll leave the testing to you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|