hagur
asked on
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+TreeViewParentTe xt+TreeVie w.Selected .text;
Or something similiar
- Hagur
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+TreeViewParentTe
Or something similiar
- Hagur
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...
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...
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(S ender: TObject);
begin
ShowMessage(GetFullPath(Tr eeview1.Se lected));
end;
meikl
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(S
begin
ShowMessage(GetFullPath(Tr
end;
meikl
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(resul t),1);
end;
meikl
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(resul
end;
meikl
ASKER
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.
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.
hi hagur,
glad to helped you,
good luck again
meikl ;-)
glad to helped you,
good luck again
meikl ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
treeview.selected.parent.t
regards,hubdog