Detecting when an object in the tree view component is selected

How do you determine if an object in the tree view component has been selected or not? Secondly, how would you select an object in code?
evansjAsked:
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.

jeurkCommented:
use the treeview.selected to get thecurrent
selected items.

if TreeView1.Selected = nil then Exit;

AnItem: TTreeNode;

AnItem:= TreeView1.Selected to retrieve
teh selected one.

To select an item by code put it's
selected property at true.

select the root of your tree :
treeview1.items[0].selected := True;
i hope it's what you want ;)
0
LischkeCommented:
Additionally, for each change in a tree view (also selection changes) the OnCHange event is triggered. So you can keep track of all things the user is doing. If you have sometimes many changes occuring in a row which might be time costly to handle each and all then use the ChangeDelay property of the tree view. If this property is > 0 the a timer is restarted each time a change occurs and only if this timer is not retriggered while waiting for its interval to timeout the OnChange event is called.

Ciao, Mike
0
evansjAuthor Commented:
What I want to do is make sure an item in the tree has been selected or not. I won't know which one until the user selects it.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

jeurkCommented:
If there is no selected node, the value of Selected is nil.
so to be sure test
if TreeView1.Selected <> nil then
I'm sure an item is selected.
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
evansjAuthor Commented:
Thanks lots!!!!
0
jeurkCommented:
You're welcome.
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.