Treeview "Explorer like" Help Needed

T

Tim Geiges

I have created a treeview for my app that on MainFormLoad I have it get
the list of drives with GetLogicalDrives() and populate the tree, then
when I click the drive it adds the first level of folders on that
drive, then click a folder and it adds the next level of folders under
the first, and so on. That part works perfectly with one flaw.

but here is the flaw:
When I add the next sub node it adds the entire path to the Node.Text
the problem is when I strip the first part of the path to display
correctly
the method does not know the rest of the path to get the directories
for the next level is, becuse the method for click basically says
treeView1.Click call GetDirectories(treeView1.SelectedNode.Text) so it
knows to get the directories from the path as in the .Text, but with
the whole path is not there it cannot get the next level

C:\
'---C:\Folder1
'---C:\Folder2
' '---C:\Folder2\Subfolder1
' '---C:\Folder2\Subfolder1\Subsubfolder1
D:\
E:\


I tried doing something like
GetDirectories(treeView1.SelectedNode.Parent +
treeView1.SelectedNode.Text) this works only for the first and second
level but then returns like "Folder2Subfolder1"
So I somehow need a loop to get the parent for each node and
concatenate to the selected node, so I can get the next folder level.

Basically the goal is to have a normal looking explorer like window
that does not have to populate the entire treeview recursively before
being used.

I am quite new to c#(only PHP before this) so any code examples would
be appreciated.

Thank you,
Tim Geiges
 
T

tal_mcmahon

So are you saying that you want the control only to load the current
level and to reload with the next level after it is clicked?
 
T

Tim Geiges

Sounds close, I want it to load the list of drives, then when I click a
drive it loads the next level under that drive, and so on for each
subfolder, is there a way to set another string along side the Text
value that I can use to store the whole path and only the last part of
the path in the Text value?
 
T

Tim Geiges

WooHoo, I solved the problem, I just realized the Tag that I can use to
pass the full path along side the short path.
 
C

Chris

You could just use recursion and build a directory path out of the parents
of the node, that way you don't store data you can generate on the fly.

Chris
 

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