We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Using popup menu in TTreeview

Medium Priority
Last Modified: 2012-05-06
Hi! I want to know how to use popup menu in TreeView. Let's say i create nodes at runtime and after i have 1 root node and 5 subnodes. So i want popup menu to show when user select any of these subnodes buy clicking right mouse button. The content of popmenu may be static or dynamic (for example contains the caption of the selected node). Obviously, popup menu may show only if right button clicked on selected node. Popup menu cannot show if right click over treeview canvas. Please kindly help
Watch Question

here is the way how I use popup menu

procedure TForm1.TreeViewMouseDown(Sender: TObject;
          Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
   tpt : TPoint;
   Node: TTreeNode;
   tpt.X := X;
   tpt.Y := Y;
   Node := TreeView.GetNodeAt(tpt.X, tpt.Y);
   if (Node = nil) or
      (length(trim(Node.Text)) = 0)  then   Exit;
   if Button = mbRight then
      PopupMenu.Popup(X+(Sender as TTreeView).ClientOrigin.X+30, Y+(Sender as TTreeView).ClientOrigin.Y-8);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Ok, very useful. And how to manage items in Popupmenu at runtime. Let's say i need to add first item as Node caption, after line break and 1 submenu with 3 items to select?

creating & using popupmenu items you can find here :

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.