I’ve done this before with a DataGridView, but is there some way to mask the visible TreeView nodes so that on a TextChanged event I can hide/filter nodes that do not contain the TextBox text? I have a lot of nodes.
Currently, this works, but it’s a “remove only” function, doesn’t add the nodes back if I delete some text from the textBox. Thanks in advance.
//Change in text will hide non matching nodes (remove only)
for (int i = 0; i<dirTree.Nodes.Count; i++)
{
if(!dirTree.Nodes[i].Text.Contains(custNameTB.Text))
{
dirTree.Nodes.RemoveAt(i);
}
}
Maybe keep a ‘Master’ node with all the nodes as children in memory. If there is no search text then just add that to the treeview. Then, if there is search text typed in, go thru the ‘master’ node and use it to create another filtered node (with the desired nodes as children) and add it to the treeview.
Basically you are just creating 2 collections on nodes. I with all the nodes (permanent) and another that just has copies of the desired node (transitory).