Yet another treeview question ....

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
LVL 3
hagurAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hubdogCommented:
you want

treeview.selected.parent.text

regards,hubdog
0
brunoheCommented:
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
kretzschmarCommented:
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

kretzschmarCommented:
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
hagurAuthor Commented:
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
kretzschmarCommented:
hi hagur,

glad to helped you,
good luck again

meikl ;-)
0
kretzschmarCommented:
oops,
forgotten to toggle the answer-radio
once again

hi hagur,

glad to helped you,
good luck again

meikl ;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.