TTreeview Parent

 I am using a ttreeview component.
 I have many parent nodes each of which
 has four child nodes. My question is
 how can I determine the parent node
 of each child in a way that will not
 produce an exception if the selected
 item is the parent. I am able to
 get the parent when a child node is
 selected, however, if you have the
 parent already selected, the program
 (index) produces an exception. I don't
 really understand ttreeview. Can anyone
 help. (Sorry for rambling!).
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.

usE the haschildren one:

with GetNodeAt(X, Y) do begin
    Selected := True;
    if HasChildren then ...;

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

You can check if the parent is assigned like this:

  If Assigned(ANode.Parent) then
    // Do something with the parent

Is this what you want?




you answered so fast, it seems you have understood the question. I haven't so please you explain it for me (because I doubt your answer has anything to do with what's asked, but I may be wrong).


as you see from my comment fro Barry I have not understood what you want. So I'm just guessing here. Can it be that you want the parent of the selected node and access properties of it (the parent) without ever testing whether the parent is valid? It isn't as hard as it might seem sometimes. If you can formulate your problem then you almost have the solution. Believe me, I have enhanced Delphi's tree view (see TreeNT at and am currently writing a totally own tree implementation (TVirtualTree). If you have further question then just ask, we can work it out :-)

Ciao, Mike
well, seems i must have understood  ;-)
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

From novice to tech pro — start learning today.