Ttreeview

This is the first time I used the Ttreeview. How could I use seperate procedure for each item in the listview? how could I know which item is selected?
factsfaceAsked:
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.

BdLmCommented:
0
factsfaceAuthor Commented:
Thank you for your response.

However, I didn't know how to deal with onclick event. since I want a procedure to be executed for every item in the treeview.  
0
JohnjcesCommented:
In your onclick event use AbsoluteIndex.

In my simple example in the snippet, you can do this with Case statements as well.

Here is a pic of a treeview with children. Each parent and child has an absoluteIndex 0 to X -1 of the number of parents and children. The image should help explain.

John

procedure Unit1.TreeView1Click(Sender: TObject);
begin
 if TreeView1.Selected.AbsoluteIndex = 0 then   // Node Status \\
  begin
   {Do something.....}
  end;
 
 if TreeView1.Selected.AbsoluteIndex = 1 then   // Cluster Config \\
  begin
   {Do something.....}
  end;
 
 if TreeView1.Selected.AbsoluteIndex = 2 then   // Network \\
  begin
   {Do something.....}
  end;
 
 if TreeView1.Selected.AbsoluteIndex = 3 then   // Virtual IP \\
  begin
   {Do something.....}
  end;
end;

Open in new window

treeview.png
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
factsfaceAuthor Commented:
Thank you very much.
Your response is highly appreciated.
0
JohnjcesCommented:
Oh... remember if you insert a new child between others, then the following treeview nodes will have their absolute index increased by one.

Plan ahead in your treeview if using AbsoluteIndex.

John
0
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.