Solved

Selecting an item from a treeview

Posted on 2006-07-19
6
159 Views
Last Modified: 2010-04-05
How do I know if I clicked on an item from the treeview and not on the root ?

thanks
0
Comment
Question by:crystyan
  • 3
  • 2
6 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
Comment Utility

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
 

Author Comment

by:crystyan
Comment Utility
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
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:crystyan
Comment Utility
thanks!
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility
No problem
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now