Use another treeview which is mysearchedTreeview at same location of mytreeview ,change the visible states of the two treenodes once searching is happend
private void txbsearch_textchange(object sender,eventArgs e)
{
if(txbsearch.Text.Length>0)
{
mySearchNodeTxt(mytreeview.nodes,txb.text);
mytreeview.visible=false;
mysearchedTreeview.visible=true;
}
else
{
mytreeview.visible=true;
mysearchedTreeview.visible=false;
}
}
private mySearchNodeTxt(TreeNodeCollection m_TreeNode, string searchtxt)
{
foreach (TreeNode Searchnode in m_TreeNode)
{
if (Searchnode.Text.ToLower().Contains(searchtxt.ToLower()))
{
mysearchedTreeview.nodes.add((TreeNode)Searchnode.Clone());
}
SearchNodeTxt(Searchnode.Nodes, searchtxt);
}
}