Solved

Point a TTreeView at C\

Posted on 2004-08-28
5
363 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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now