Click here to Skip to main content
15,867,835 members

Comments by brunofer2007 (Top 3 by date)

brunofer2007 15-Jan-12 5:59am View    
Deleted
just replace the logical comparison "n.Text[0] < temp.Text[0]" with other comparison logical.
It have to be a TreeNode property.
brunofer2007 14-Sep-11 6:36am View    
Deleted
1 - Sometimes a TreeView doesn't have necessarily a datasource. The nodes could be added manually (that was my case).


2 - If you watch carefully the code, you see that recursive function it's only called when a node has childnodes:

foreach (TreeNode n in node.ChildNodes)
sort(n);

the recursive function is called as many child nodes you have, so you can predict the number of iterations


3 - I'll explain this step to you:

- temp variable is initialized to null.

- for each child node: if the temp is null, temp = childnode.
if temp != null,
if the first character of childNode < fisrt character of Temp, temp = childNode

- when you reach the end of for each statment, the Temp variable has the lowest start character node.

- add that node to List "childs", this way the list will be filled alphabetically.

- delete temp node from child node.

- start all over again (the temp variable is set to null to store again the lowest start letter node).

- this cycle stops when there are no more childnodes:
while(node.ChildNodes.Count>0)

- then, you simply add again the childnode in the node (alphabetically sorted):
foreach (TreeNode a in childs)
node.ChildNodes.Add(a);


4 - and finally, as I mention before, the sort() method for TreeView is not present on WebForms (ASP.NET).
brunofer2007 12-Sep-11 4:21am View    
Deleted
Hello George,
as you can see in the title, this solution is for ASP.NET TreeView control.
The method you mentioned works fine in WinForms Controls, but it's not present on this WebForm control.