Filtering a TreeView I use the code below for filtering a treeview. Can this be improved?

private IEnumerable&lt;TreeNode&gt; FindNodeByValue(TreeNodeCollection nodes, string searchstring)
 {


    foreach (TreeNode node in nodes)
    {
        if (node.Value.IndexOf(searchstring,
              StringComparison.CurrentCultureIgnoreCase) &gt;= 0)
            yield return node;
        else
        {
            foreach (var subNode in FindNodeByValue(node.ChildNodes, searchstring))
                yield return subNode;
        }
    }
}

protected void Button1_Click(object sender, EventArgs e)
{

    var query= FindNodeByValue(TreeView1.Nodes, fieldFilterTxtBx.Text);
    if (query != null)
    {
        //TreeView1.Nodes[0].Expand();
        //TreeView1.Nodes.Clear();
        foreach (TreeNode node in query.ToList())
        {
            TreeView1.Nodes.Add(node);

        }


        //  TreeNode newnode = new TreeNode("Detail Engineering");
        // TreeView1.Nodes.Add(newnode);

        TreeView1.ExpandAll();
    }

    else
    {

        Label1.Text = "No file found";

    }
}
What's the problem with your implementation? You clear the tree and add new (filtered) nodes. Somehow, TreeView1.Nodes.Clear(); is under comment, so it may be supposed that you want to preserve full node structure. If so, just store it in memory:

var query = FindNodeByValue(PersistentNodeSet.Nodes, fieldFilterTxtBx.Text);
if (query != null)
{
    TreeView1.Nodes.Clear();
    foreach (TreeNode node in query.ToList())
        TreeView1.Nodes.Add(node);
    TreeView1.ExpandAll();
}


And if you want the tree to preserve original structure, you need to use recursion in FindNodeByValue().