?
Solved

Using popup menu in TTreeview

Posted on 2009-02-10
3
Medium Priority
?
1,857 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
0
Comment
Question by:Alexander_Savenko
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
bokist earned 2000 total points
ID: 23598637
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;
0
 

Author Comment

by:Alexander_Savenko
ID: 23598873
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?
0
 
LVL 6

Expert Comment

by:bokist
ID: 23599070
creating & using popupmenu items you can find here :

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20634719.html
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question