[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Navigating Treeview

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
DPomeroy
Asked:
DPomeroy
  • 4
  • 2
1 Solution
 
DPomeroyAuthor Commented:
Edited text of question
0
 
DPomeroyAuthor Commented:
This is the second time I've asked this question.  I guess I wasn't clear the first time.
0
 
goochCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sperlingCommented:
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
 
DPomeroyAuthor Commented:
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
 
DPomeroyAuthor Commented:
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
 
sperlingCommented:
>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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now