Seven price
asked on
treeview sorting childnodes
Dim rootDir As New DirectoryInfo(Server.MapPa th("~/loca tion/"))
Dim d As DateTime
Dim RootNode As TreeNode = RecurseNodes(rootDir)
Treeview1.Nodes.Add(RootNo de)
SortTreeNodes(RootNode.Par ent.ChildN odes)
RootNode.SelectAction = TreeNodeSelectAction.None
Dim subDirs As DirectoryInfo() = rootDir.GetDirectories()
trying to sort in descending order using code below. when I had 2 nodes the bottom node moved to the middle. but 3 nodes is a problem I cannot get it to move at all.
Dim d As DateTime
Dim RootNode As TreeNode = RecurseNodes(rootDir)
Treeview1.Nodes.Add(RootNo
SortTreeNodes(RootNode.Par
RootNode.SelectAction = TreeNodeSelectAction.None
Dim subDirs As DirectoryInfo() = rootDir.GetDirectories()
trying to sort in descending order using code below. when I had 2 nodes the bottom node moved to the middle. but 3 nodes is a problem I cannot get it to move at all.
Private Sub SortTreeNodes(treeNodes As TreeNodeCollection)
Dim sorted = True
For Each treeNode As TreeNode In treeNodes
SortTreeNodes(treeNode.ChildNodes)
Next
Do
sorted = True
For i = 0 To treeNodes.Count - 1
Dim treeNode1 = treeNodes(i)
Dim treeNode2 = treeNodes(i)
Dim treeNode3 = treeNodes(i + 1)
' If treeNode1.Text.CompareTo(treeNode3.Text) < 0 Then
treeNodes.RemoveAt(i)
treeNodes.RemoveAt(i)
treeNodes.RemoveAt(i)
treeNodes.AddAt(i, treeNode1)
treeNodes.AddAt(i, treeNode2)
treeNodes.AddAt(i, treeNode3)
Response.Write(i)
' End If
Next
Loop While Not sorted
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
also in my page load I have
Dim RootNode As TreeNode = RecurseNodes(rootDir)
Treeview1.Nodes.Add(RootNo de)
sort(RootNode)
not sure it is working nothing seems to be effected.
Dim RootNode As TreeNode = RecurseNodes(rootDir)
Treeview1.Nodes.Add(RootNo
sort(RootNode)
not sure it is working nothing seems to be effected.
ASKER
thanks I got it.
OrElse (n.Text(1) > temp.Text(0))) Then
OrElse (n.Text(1) > temp.Text(0))) Then
ASKER
Open in new window
I did that but I need to have it descending instead of ascending.