如何在c#net中搜索类似Outlook的树节点文本?
我正在使用Infrastics工具进行C#.Net项目。在我的项目中,我希望实现搜索选项,如Microsoft Office Outlook 2007搜索功能。演示使用System.Windows.Forms.TreeView的示例。假设基础设施树视图也可以这样做。关键是在处理树时使用递归方法:如何在c#net中搜索类似Outlook的树节点文本?,c#,winforms,C#,Winforms,我正在使用Infrastics工具进行C#.Net项目。在我的项目中,我希望实现搜索选项,如Microsoft Office Outlook 2007搜索功能。演示使用System.Windows.Forms.TreeView的示例。假设基础设施树视图也可以这样做。关键是在处理树时使用递归方法: // Returns the node with the first hit, or null if none public TreeNode Search(TreeView treeV
// Returns the node with the first hit, or null if none
public TreeNode Search(TreeView treeView, string text)
{
return SearchNodes(treeView.Nodes, text);
}
// Recursive text search depth-first.
private TreeNode SearchNodes(TreeNodeCollection nodes, string text)
{
foreach (TreeNode node in nodes)
{
if (node.Text.Contains(text)) return node;
var subSearchHit = SearchNodes(node.Nodes, text);
if (subSearchHit != null) return subSearchHit;
}
return null;
}
你到底想要什么?搜索算法的实现,或者它的GUI部分——检索输入和显示搜索结果?