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?
jeurkConnect With a Mentor Commented:
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.
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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.
evansjAuthor Commented:
Thanks lots!!!!
You're welcome.
All Courses

From novice to tech pro — start learning today.