nitin 0

nitin 0

  • NA
  • 18
  • 0

TreeView Control Performance REALLY LOW on searching a Node

Jan 30 2004 5:14 AM
I have more than 20, 000 nodes , parent node having sub nodes and again subnodes exactly like windows explorer structure with files and folders. I populate the tree on "afterexpand" event by passing the parentnodeid and getting child nodes. The problem is with the search, suppose I want to search a particular node I check the Tag property of currentnode to my searchnode and search recursively but the problem is since I donot have treeview loaded I have to call tnode.expand() to populate the parentnode with chlid nodes and then I see if Tag property of my search node matches one by one with child nodes, if not drill to sub levels further and do the same. To expand each node one by one and check for search node takes hell lot of time. Can anyone suggest better way .Here is the code below public void SearchRecursive(TreeNode ParentNode, TreeNode MyTreeNode) { foreach (TreeNode tNode in ParentNode.Nodes) { if (tNode.Tag.ToString() == MyTreeNode.Tag.ToString()) { this.treeView1.SelectedNode = tNode; this.treeView1.SelectedNode.EnsureVisible(); break; } else { tNode.Expand(); if (tNode.GetNodeCount(true) > 0) SearchRecursive(tNode,MyTreeNode); } } }

Answers (5)