Solved

Selecting an item from a treeview

Posted on 2006-07-19
6
164 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 125 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
Independent Software Vendors: 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

Technology Partners: 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!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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