Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TreeView for folder tree

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
SE
Greetings all...

For my "whereisit" clone I'm going to have a Tree structure of the CD (or hdd). I already have a function that will enable the program to search and find every folder (and files, optional)... my problem is how to write the funtion for adding every folder / subfolder to the TreeView component, and in correct order, at runtime. could anyone give me a hint on how to do it?
Or a sample code I could work with would be great!!

I have absolutely no idea how to do it... though when observing the CDirectoryOutline component talked about nodes and childnodes! (or something like that)

Thanks for anyhelp.. My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
use FindFirstFile/FindNextFile in a recursive procedure on creatint the tree John Fill
1c.bmp


ivfmd@mail.md
 
Could you explain that a little bit more?? My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
FindFirstFile/FindNextFile are WInAPI functions. Read the help on how to work with them. John Fill
1c.bmp


ivfmd@mail.md
 
John,

I think that 801119's problem is with the TreeView. He has the algorithm for finding the directories but he can't figure out how to display them on a TreeView. Am I correct on that assumption 801119?

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
yes, that's true 2ffat... my only problem is to display them as a directory tree, much similar to the CDirctoryOutline component! My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Let's start with the basics and then if you get stuck you can post your problem here. TTreeView uses nodes to tell how the view should look. The top node can also be called the root node or parent. For example, a root node on a TreeView for a directory could use as the drive numbers (A,C,D,E, etc). To add these nodes you would use the Add command.
Code:
CDriveNode = TreeView1->Items->Add(NULL, "C:"); // use if you
intend to call CDrive via Add or Insert
TreeView1->Items->Add(NULL, "C:"); // use if you do not intend to use Add or
 Insert
Notice that the first argument in Add is a null here. This argument tells Add which node to add the string to. Since it is null, it adds it to the root. Nodes or items off the root node are called child nodes (children). You can use the above Add or another way to add a child node is to use AddChild.
Code:
// One option to add children 
FirstDirectoryNode = TreeView1->Items->AddChild(CDriveNode, "MyDirectory");
TreeView1->Items-AddChild(CDriveNode, "YourDirectory");

// Another option to add children
int J = 0;
TreeView1->Items-AddChild(CDriveNode->Item[J], "MyDirectory");
J++;
TreeView1->Items-AddChild(CDriveNode->Item[J], "YourDirectory");
J++;
// This might be more like what you want for a directory listing.

// Yet another option to add children
TTreeNode* aDirectory = TreeView1->Items->Add(CDriveNode, "MyDirectory");
TreeView1->Items-AddChild(CDriveNode, "YourDirectory");
Play around with this and see how far you can get. As usual, I'm doing this from notes and memory and I haven't tested the code.

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
One question before I can start and "play around" with the code...

When doing the
Code:
CDriveNode = TreeView1->Items->Add(NULL, "C:\\" );
version, I get the message (which Is not comming as a suprise) "Undefined symbol 'CDriveNode'"
Could you please explain what I should write prior to CDriveNode .... line!?!
thanks again My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
Opps! I've forgotten to define my variables alot lately. CDriveNode should be set up in your header file under private: // User Declarations. It should be defined as a pointer to a TTreeNode. Something like this:
Code:
TTreeNode *CDriveNode;
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top