943,096 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 860
  • ASP.NET RSS
Feb 8th, 2010
0

Treeview Sorting Perfomance

Expand Post »
Good Day All.

Am binding the treeview from a Database and it gets populated and am sorting it after this way

ASP.NET Syntax (Toggle Plain Text)
  1. SortTree(CurriculumTreeView);


ASP.NET Syntax (Toggle Plain Text)
  1. private void SortTree(TreeView tv)
  2. {
  3. if (tv.Nodes != null)
  4. {
  5. for (int i = 0; i < tv.Nodes.Count; i++)
  6. {
  7. TreeNode node = tv.Nodes[i];
  8. SortNode(node);
  9. }
  10. }
  11. }

ASP.NET Syntax (Toggle Plain Text)
  1. private void SortNode(TreeNode node)
  2. {
  3. if (node.ChildNodes != null && node.ChildNodes.Count > 1)
  4. {
  5. for (int i = 0; i < node.ChildNodes.Count; i++)
  6. {
  7. TreeNode childNode = node.ChildNodes[i];
  8. SortNode(childNode);
  9. SortNodes(node.ChildNodes);
  10. }
  11. }
  12. }

ASP.NET Syntax (Toggle Plain Text)
  1. private void SortNodes(TreeNodeCollection nodes)
  2. {
  3. if (nodes == null || nodes.Count < 2)
  4. {
  5. return;
  6. }
  7. for (int i = 0; i < nodes.Count - 1; i++)
  8. {
  9. for (int j = 0; j < nodes.Count - 1; j++)
  10. {
  11. TreeNode node = nodes[j];
  12. TreeNode nextNode = nodes[j + 1];
  13. if (node.Text.CompareTo(nextNode.Text) > 0)
  14. {
  15. TreeNode tempNode = new TreeNode();
  16. tempNode = nextNode;
  17. nodes.Remove(nextNode);
  18. nodes.AddAt(i, tempNode);
  19. }
  20. }
  21. }
  22. }



when i don't sort, everything is faster, but now with this sorting its very slow and end up timing out.

Thanks
Similar Threads
Reputation Points: 31
Solved Threads: 14
Posting Whiz
vuyiswamb is offline Offline
310 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: link problem
Next Thread in ASP.NET Forum Timeline: Input string was not in a correct format. Error is coming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC