?
Solved

Selecting an item from a treeview

Posted on 2006-07-19
6
Medium Priority
?
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
ID: 17141183

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
ID: 17141727
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
ID: 17141777

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:crystyan
ID: 17142846
thanks!
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17143505
No problem
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 17144906
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

770 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