?
Solved

Point a TTreeView at C\

Posted on 2004-08-28
5
Medium Priority
?
383 Views
Last Modified: 2010-04-05
How do I tell a TTreeView to display C:\ ?
It has methods to manipulate the nodes once the tree is loaded, and methods to load it manually with individual items,  but I can't find a way to just point it at C:\ and have it fill itself with all the directories of C:\.
LoadFromFile('C:\') =  error.

0
Comment
Question by:frog
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:LMuadDIb
ID: 11924505
Not possible to load a directory structure directly into a treeview.
you would have to parse evreything manually and insert them yourselve.

you should try some 3rd party components like LsFileExplorer & LsFileList... both are freeware w/ source and it will save you alot of time.
you can get it here: http://delphi.icm.edu.pl/ftp/d30free/FileExpl.zip 
0
 

Author Comment

by:frog
ID: 11925222
Thanks  LMuadDIb,
They are impressive components!

I want to use a TgfglTreeView which has a checkbox at each node for selection of directories.
(Both it and TTreeview say they can be used for display/selection of disk directories, they forget to say that it is very unwieldy to attempt to use them in that way!)

0
 
LVL 12

Expert Comment

by:esoftbg
ID: 11928446
it is possible,
download a working example from:
page:        http://www.geocities.com/esoftbg/
  link:        Q_21041851.zip        Finding node in a treeshellview
0
 
LVL 4

Accepted Solution

by:
LMuadDIb earned 500 total points
ID: 11928555
Ok, you would probably use the delphi functions "FindFirst", "FindNext" and "FindClose" to do this.
there are 2 ways to go about this I think. depending on what you need to be done.

1 way is to recursively search thru a directory or partition and throw ALL the results into the treeview.
This way can be slow and intensive especially if your trying to gather a large directory structure. But once its done, its done.

2nd way is to do it directory by directory whenever the user enters a certain directory.

A great example of a recursive search with a TTreeview can be found here:
http://www.awitness.org/delphi_pascal_tutorial/source3/treeview_disk_scan.zip

I also have a recursive dir search function in a console application I made, which I can post if the above example doesnt help you.
But basically its the same as above example.

for the 2nd way you would have to use something similiar to this:

procedure ListFileDir(Path: string; tv: TTreeview);
var
  SR: TSearchRec;
  TempNode : TTreeNode;
begin
  if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
  begin
    repeat
      if (SR.Attr = faDirectory) then
      begin
        TempNode := tv.Items.Add(nil, SR.Name); { Add a root node }
        { give it an image and other stuff next }
        TempNode.ImageIndex := 0; { Dir Image Generic }
      end;
      if (SR.Attr <> faDirectory      ) then
      begin
        TempNode := tv.Items.Add(nil, SR.Name); { Add a root node }
        { give it an image and other stuff next }
        TempNode.ImageIndex := 1; { File Image Generic }
      end;
    until FindNext(SR) <> 0;
    FindClose(SR);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListFileDir(edit1.Text, treeview1);
end;

Of course this is an extremely simple example, and it only puts the dir listing in the root of treeview.
You would have to keep track of the slected treeview node, and insert the listing inside that node etc...
Its like I said, it will take quite a bit of code to do it manually

My advise, would be to use the recursive method.
hope this helps
0
 

Author Comment

by:frog
ID: 11946723
Thanks  LMuadDIb,
The link provided a good example (and plenty of other good info!). I have adapted the example and it does exactly what I want.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question