I've a treeview and I want to search for a particular node everywhere in the treeview and when it finds it, it need to collapse it. I've the following code but it doesn't seem to do the collapsing, if anyone has any idea please post some tips. Thanks in advance
private void FindByText()
{
TreeNodeCollection nodes = treeView1.Nodes;
foreach (TreeNode n in nodes)
{
FindRecursive(n);
}
}
private void FindRecursive(TreeNode treeNode)
{
string collapseStr = "";
foreach (TreeNode tn in treeNode.Nodes)
{
collapseStr = tn.ToString();
if (collapseStr.StartsWith("sub1"))
tn.Collapse();
FindRecursive(tn);
}
}
It needs to collapsing all the node = "sub1" below.
Node1
sub1
sub2
sub3
Node2
sub1
sub2
sub3
Loading
John QPosted Jan 22, 2014, 1:48 PM
VulpesPosted Jan 22, 2014, 10:36 AM
collapseStr = tn.ToString();
It should be:
collapseStr = tn.Text;