2

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:

  • I have my VST close to a listview.
  • I can only multi select root nodes with the mouse (hold mousebutton and move the mouse)
  • If I click on ANY child node (right or left) - it is selected (+ [VSelected] State)
  • If I right click on a root node it selects automatically and opens a popupmenu.

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.

TLama
  • 75,147
  • 17
  • 214
  • 392
Ben
  • 3,380
  • 2
  • 44
  • 98

2 Answers2

6

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.

TLama
  • 75,147
  • 17
  • 214
  • 392
2

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.

jpfollenius
  • 16,456
  • 10
  • 90
  • 156
  • thank you. I guess missed that event because I was so focused to look for something with right click. – Ben Aug 14 '12 at 06:39
  • 5
    I know what you mean. The number of options and events on virtual tree view can be overwhelming at first :) – jpfollenius Aug 14 '12 at 06:51