• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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