Solved

Point a TTreeView at C\

Posted on 2004-08-28
5
360 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

16 Experts available now in Live!

Get 1:1 Help Now