Solved

Point a TTreeView at C\

Posted on 2004-08-28
5
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

733 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