Please Help! IE Treeview control

G

Guest

Hello All,

I having a small problem. I wrote a procedure to add nodes
to my IE Treeview control and all nodes are added. Now,
the problem is that all the nodes are added in the Root
node. Some of the nodes should be added as a child node.
Here is my procedure, Can someone troubleshoot this code
please:

Dim strDirectories As String()
Dim strDirectory As String
Dim strFile As String
Dim nodDirectory As TreeNode
Dim nodFile As TreeNode

strDirectories = Directory.GetDirectories(Server.MapPath
("PDF"))

For Each strDirectory In strDirectories
nodDirectory = New TreeNode
nodDirectory.Text = strDirectory.Substring
(strDirectory.LastIndexOf("\") + 1)
Me.tvMenu.Nodes.Add(nodDirectory)
For Each strFile In Directory.GetFiles
(strDirectory)
nodFile = New TreeNode
nodFile.Text = strFile.Substring
(strFile.LastIndexOf("\") + 1)
Me.tvMenu.Nodes.AddAt(strDirectory,
nodFile)
Next
Next
 
A

Ayende Rahien

Hello All,

I having a small problem. I wrote a procedure to add nodes
to my IE Treeview control and all nodes are added. Now,
the problem is that all the nodes are added in the Root
node. Some of the nodes should be added as a child node.
Here is my procedure, Can someone troubleshoot this code
please:

Dim strDirectories As String()
Dim strDirectory As String
Dim strFile As String
Dim nodDirectory As TreeNode
Dim nodFile As TreeNode

strDirectories = Directory.GetDirectories(Server.MapPath
("PDF"))

For Each strDirectory In strDirectories
nodDirectory = New TreeNode
nodDirectory.Text = strDirectory.Substring
(strDirectory.LastIndexOf("\") + 1)

Do this:
MyTmpNode = new TreeNode(nodeDirectory)

Me.tvMenu.Nodes.Add(MyTmpNode)
For Each strFile In Directory.GetFiles
(strDirectory)
nodFile = New TreeNode
nodFile.Text = strFile.Substring
(strFile.LastIndexOf("\") + 1)
MyTmpNode.Nodes.Add(nodFile)

Me.tvMenu.Nodes.AddAt(strDirectory,
nodFile)

If I understand this line currectly, this tells the tree view to insert a
new node after a node with the text strDirectory AT THE SAME LEVEL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top