• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Selecting an item from a treeview

How do I know if I clicked on an item from the treeview and not on the root ?

thanks
0
crystyan
Asked:
crystyan
  • 3
  • 2
1 Solution
 
Russell LibbySoftware Engineer, Advisory Commented:

You could perform something like this in the OnClick event of the tree.

procedure TForm1.TreeView1Click(Sender: TObject);
var  ptTree:        TPoint;
     tnItem:        TTreeNode;
begin

  ptTree:=TreeView1.ScreenToClient(Mouse.CursorPos);
  tnItem:=TreeView1.GetNodeAt(ptTree.X, ptTree.Y);
  if Assigned(tnItem) and (tnItem.Level > 0) then
  begin
     ShowMessage('Item was clicked');
  end;

end;

---

Russell
0
 
crystyanAuthor Commented:
how do I check this if I`m not in the onclick event ?
for example when I push a button I want to check if an item is selected and not the root.

thanks
0
 
Russell LibbySoftware Engineer, Advisory Commented:

var  tnItem:        TTreeNode;
begin

  tnItem:=TreeView1.Selected;
  if Assigned(tnItem) and (tnItem.Level > 0) then
  begin
     ShowMessage('Item is selected and its not a level 0');
  end;

end;


Regards,
Russell
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
crystyanAuthor Commented:
thanks!
0
 
Russell LibbySoftware Engineer, Advisory Commented:
No problem
0
 
kretzschmarCommented:
would it not easier to look for an assigned parentnode?

 if Assigned(tnItem) and assigned(tnItem.parent) then  //no root

well, guess it makes no difference

meikl ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now