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?
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 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 ;)
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
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.
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.

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.

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!!!!
You're welcome.
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.