Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

right click...

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
Xperl
Asked:
Xperl
  • 6
  • 5
  • 4
1 Solution
 
kretzschmarCommented:
set the option rightclickselect or similar to true in the tree option propertys
0
 
EpsylonCommented:
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
 
XperlAuthor Commented:
kretzschmar, i checked for a rightclickselect in the property but there isn't one.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
XperlAuthor Commented:
epsylon, there is no OnContextPopup event either.

I'm using delphi 2 if that makes a difference.
0
 
kretzschmarCommented:
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
 
EpsylonCommented:
> 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
 
EpsylonCommented:
I guess the GetNodeAt() method is not there eighter in D2..?
0
 
kretzschmarCommented:
don't know, eps, long time ago as i used d2
0
 
EpsylonCommented:
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
 
XperlAuthor Commented:
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
 
kretzschmarCommented:
>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
 
XperlAuthor Commented:
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
 
kretzschmarCommented:
if you want, then its ok for me too :-)
0
 
EpsylonCommented:
>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
 
EpsylonCommented:
Thanks a lot for the points, Xperl.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now