Ben
Ben

Reputation: 3440

VirtualStringTree OnNodeRightClick

I am looking for a procedure or something that gets fired if I right click on a Node (or in general on the VirtualStringTree)

I have the following scenario:

Now I would like to have a different popupmenu for ( 1 common ) for all my child nodes (and only if they are selected).

Hope you can understand what I mean, thank your for your help.

Upvotes: 2

Views: 3566

Answers (2)

TLama
TLama

Reputation: 76693

I won't answer your question but point you to the right event since you've said you want to have different popup menu for each node. The right click solution would have a weakness at least in missing menu key press which invokes the popup menu as well.

1.1 How to use different popup menu for each node depending on node level ?

procedure TForm1.VirtualTreeGetPopupMenu(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; const P: TPoint;
  var AskParent: Boolean; var PopupMenu: TPopupMenu);
begin
  case VirtualTree.GetNodeLevel(Node) of
    0: PopupMenu := PopupMenu1;
    1: PopupMenu := PopupMenu2;
  end;
end;

1.2 How to enable right mouse button click node selection ?

And to allow the right mouse button node selection, simply add the toRightClickSelect option to the TreeOptions.SelectionOptions option set.

Upvotes: 6

jpfollenius
jpfollenius

Reputation: 16612

You can use the normal OnMouseDown event, make sure the Button is mbRight and then use the GetHitTestInfoAt function to check which node is under the cursor (if there is any).

var
  HitInfo : THitInfo;
...
TreeView.GetHitTestInfoAt(X, Y, HitInfo);
if (HitInfo.Node = ?) and (HitInfo.Column = ?) then
  begin
  ...
  end;

There is also OnGetPopupMenu which gives you a node and a column and lets you return any TPopupMenu.

Upvotes: 2

Related Questions