Search code examples
delphi-7virtualtreeviewdelphitvirtualstringtree

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:

  • 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.


Solution

  • 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.