Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can popup a context menu in a treeview but just in some particular treenodes?

Tags:

delphi

I have a TPopupMenu associated with a TTreeView, but i now want to invoke (popup) the menu only when the user click in a particular node. So how i can popup a context menu in a treeview but just in some particular treenodes?

like image 853
Salvador Avatar asked Dec 21 '22 23:12

Salvador


2 Answers

Use the Handled parameter from the OnContextPopup event. By setting this parameter to True you will suppress the context menu to display. The following code shows how to get the TTreeNode from the cursor position passed into the OnContextPopup event and it displays the popup menu only when you right click over the TTreeNode different from the top one.

procedure TForm1.TreeView1ContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
begin
  if TreeView1.GetNodeAt(MousePos.X, MousePos.Y) = TreeView1.TopItem then
    Handled := True;
end;
like image 155
TLama Avatar answered Dec 24 '22 02:12

TLama


This might be helpful:

procedure TForm1.TreeView1ContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
  var node : TTreeNode;
begin
  node := TreeView1.GetNodeAt(MousePos.X, MousePos.Y);
  if not Assigned (node) then
    Abort;
end;
like image 20
Azad Avatar answered Dec 24 '22 00:12

Azad