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

x

Using popup menu in TTreeview

Alexander_Savenko
on
Medium Priority
2,084 Views
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
Comment
Watch Question

Commented:
here is the way how I use popup menu

procedure TForm1.TreeViewMouseDown(Sender: TObject;
          Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
   tpt : TPoint;
   Node: TTreeNode;
begin
   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);
end;

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

Ask the Experts

Author

Commented:
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?

Commented:
creating & using popupmenu items you can find here :

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20634719.html
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.

OR

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.