Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#net中搜索类似Outlook的树节点文本?_C#_Winforms - Fatal编程技术网

如何在c#net中搜索类似Outlook的树节点文本?

如何在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

我正在使用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 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部分——检索输入和显示搜索结果?