Solved

Navigating Treeview

Posted on 1997-04-19
7
212 Views
Last Modified: 2010-04-04
How do I navigate up the path from a child node.  I need to get the path from the root of the tree to the farthest child, but I need to start at the child.  
0
Comment
Question by:DPomeroy
[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
  • 4
  • 2
7 Comments
 

Author Comment

by:DPomeroy
ID: 1335515
Edited text of question
0
 

Author Comment

by:DPomeroy
ID: 1335516
This is the second time I've asked this question.  I guess I wasn't clear the first time.
0
 

Expert Comment

by:gooch
ID: 1335517
By farthest, do you mean the deepest child??  The one with the
longest search path??  I don't see how you'll be able to search for the child with the deepest search path starting at an arbitrary child.  If you start at the root, sure.

I suppose one could write an algorithm to start at all leaf nodes then progress to the root, finally giving you the leaf node (child) that had the longest path.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1335518
If I understand your question right, this should be what you're looking for.

This is a simple form with a TTreeView called 'TV' and a TLabel called 'Label1'

Add the following code to TV.OnClick...

procedure TForm1.TVClick(Sender: TObject);
var
  ANode : TTreeNode;
  s     : STRING;
begin
  // Set ANode to the starting node
  ANode := TV.Selected;

  // Set the last "Subdirectory" of the path
  s := ANode.Text;
  repeat
    // Get the parent node
    ANode := ANode.Parent;
   
    // If not nil, insert in beginning of path
    if ANode <> nil then s := ANode.Text + '\' + s;

  until ANode = nil;

  Label1.Caption := s;
end;



0
 

Author Comment

by:DPomeroy
ID: 1335519
I don't know if this will work so its hard to grade.  Thanks for the help.  I didn't see parent in the treenodes property.  How did you figure out it had a parent property?
Thanks again.
Dave Pomeroy
0
 

Author Comment

by:DPomeroy
ID: 1335520
Great answer.  I would like to pay for this information.  The answer is simple but I am learning the object part of Delphi and am struggling.  It helped a lot.  
0
 
LVL 3

Expert Comment

by:sperling
ID: 1335521
>I don't know if this will work so its hard to grade. Thanks for

Try it out first, and then grade it. That's what you ought to do for all questions. If not, I could just give you a nonsense answer, and after grading it there's nothing you can do about it.

>the help. I didn't see parent in the treenodes property. How did
>you figure out it had a parent property?

I looked in the source ;)

Regards,

Erik.

0

Featured Post

Industry Leaders: 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 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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month4 days, 13 hours left to enroll

636 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