[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Yet another treeview question ....

Posted on 2000-01-08
7
Medium Priority
?
216 Views
Last Modified: 2010-08-05
I've got one treeview which displays a directory and it's subdirectorys and files.

When I double click a node in the treeview, I'd like to get the filename I clicked and the full path.

I almost have this right, all I do is that I take the start path the treeview displays, and then Treeview.Selected.Text, but when there's a parent node in between, the path will not be correct.

So, basically what I need is to find out whether the selected node has a parent, and if it does, I need it's caption.
There fore:

Filename := Startpath+TreeViewParentText+TreeView.Selected.text;

Or something similiar

- Hagur
0
Comment
Question by:hagur
7 Comments
 
LVL 2

Expert Comment

by:hubdog
ID: 2334802
you want

treeview.selected.parent.text

regards,hubdog
0
 

Expert Comment

by:brunohe
ID: 2334810
I see your problem. The most easiest thing is to write with every node a class or record containing the entire path to file file/folder and hang it on the node (TTreeNode.Data).

Another possibility is to loop on the treeview as long as the parent/actual node is valid.

I would prefer the first. Depends on you...
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2334846
hi hagur,

you can do something like this

Function GetFullPath(Node : TTreeNode) : String;
begin
  Result := '';
  While Node <> Nil do
  Begin
    Result := Node.Text + '\'+Result;
    Node := Node.Parent;
  end;
end;


procedure TForm1.TreeView1DblClick(Sender: TObject);
begin
  ShowMessage(GetFullPath(Treeview1.Selected));
end;

meikl
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2334852
oops,

there will be a backslash to much,

the correction:

Function GetFullString(Node : TTreeNode) : String;
begin
  Result := '';
  While Node <> Nil do
  Begin
    Result := Node.Text + '\'+Result;
    Node := Node.Parent;
  end;
  Delete(Result,Length(result),1);
end;

meikl
0
 
LVL 3

Author Comment

by:hagur
ID: 2334882
HubDog,

Although tree.selected.parent.text works, and infact I had already done that, what if the selected node had no parent?  I get an access violation.
So what I really needed was a way to figure out how to determine whether a specified node *had* a parent, and if it did, then do something similar to what you said.

As for kretzschmar, your solution worked
perfectly.

Post your comment as an answer and you'll receive my points.

HubDog, thanks for your input anyway.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2334936
hi hagur,

glad to helped you,
good luck again

meikl ;-)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 2334939
oops,
forgotten to toggle the answer-radio
once again

hi hagur,

glad to helped you,
good luck again

meikl ;-)
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

608 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