Solved

right click...

Posted on 2001-07-13
15
178 Views
Last Modified: 2010-04-04
I am using a treeview with a popup menu assigned to it.  When i right click on the treeview the popup menu works ok but the problem is i want to be able to right click on a node, highlight it and get the node selected.index returned so that when i choose a command on the popup menu it knows what node i am working with.

any ideas?
0
Comment
Question by:Xperl
[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
  • 6
  • 5
  • 4
15 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6279830
set the option rightclickselect or similar to true in the tree option propertys
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6279852
Use the TTreeView.OnContextPopup event:

procedure TForm1.TreeView1ContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
begin
  TreeView1.Selected := TreeView1.GetNodeAt(MousePos.x, MousePos.y);
  Menu1.Caption := TreeView1.GetNodeAt(MousePos.x, MousePos.y).Text;
end;
0
 

Author Comment

by:Xperl
ID: 6279853
kretzschmar, i checked for a rightclickselect in the property but there isn't one.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:Xperl
ID: 6279858
epsylon, there is no OnContextPopup event either.

I'm using delphi 2 if that makes a difference.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6279865
delphi2, yes this makes sure a difference :-)

but i guess you can use eps code in the mousedown-event,
just check the mousebutton-before
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6279873
> I'm using delphi 2 if that makes a difference.

>> Sigh <<

Why do people never say which version they use when they ask a question? It is trivial information.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6279878
I guess the GetNodeAt() method is not there eighter in D2..?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6279887
don't know, eps, long time ago as i used d2
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 150 total points
ID: 6279898
With OnMouseDown it would be (Menu1 is a menu item):

procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 TreeView1.Selected := TreeView1.GetNodeAt(X, Y);
 Menu1.Caption := TreeView1.GetNodeAt(X, Y).Text;
end;
0
 

Author Comment

by:Xperl
ID: 6279909
sorry epsylon - it's late here and sleep has been knocking on the door for hours but i have tried to ignore it to get a few bugs in my program sorted out.

i have arranged to have myself smacked around the head with a wet lettuce at a leter date as punishment for not giving the version number in the original question.

the good news of course is that the code you gave me seems to have worked when i put it into the mousedown event and changed the code to:

TreeView1.Selected := TreeView1.GetNodeAt(x, y);
label1.Caption := TreeView1.GetNodeAt(x, y).Text;

one thing though, what does the MousePos do and am losing something by removing it?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6279924
>one thing though, what does the MousePos do and am losing something by removing it?
what mousepos?

if you mean x,y you need it only to select the rightclicked node, maybe you should check, if a node if afterwards really selected

TreeView1.Selected := TreeView1.GetNodeAt(x, y);
if assigned(TreeView1.Selected) then
  label1.Caption := TreeView1.selected.Text;

0
 

Author Comment

by:Xperl
ID: 6279958
thanks kretzschmar.  I will accept the answer eps gave but i shall post some points for you too for your help.

is that ok?  
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6279963
if you want, then its ok for me too :-)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6279976
>i have arranged to have myself smacked around the head with a wet lettuce at a leter date as punishment
for not giving the version number in the original question.

with a wet lettuce..?  :o)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6279991
Thanks a lot for the points, Xperl.
0

Featured Post

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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month5 days, 3 hours left to enroll

636 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