Its a dumb question maybe but I have a popup menu which is linked with many TTreeViewItems. The problem is that the TTreeView.Selected property never gets set on right click. The GetMousePos is prone to returning the next or the previous TTreeViewItem's coordinates. How can I get the Item which actually triggered the popup?
How to get the tree-view item which triggered a popup menu?
1.9k views Asked by Umair Ahmed At
2
seems
TPopupMenu.PopupPoint
returns(0,0)
point when you click item in PopupMenu (In Delphi XE2, docwiki says that it is used internally to set position of menu, and seems it is set to 0 when menu dissapears). so in this situation, seems to me, the easiest way is to handleTreeView.OnMouseDown
where you can save reference to selected item, and then use it in Popup item event handler;so, in the exmaple code below i've added
FClickedItem : TTreeViewItem
into the form class;UPDATE: i've just browsed the source code, private variable
TPopupMenu.FPopupPoint
(readonly property) is not used in implementation code, thats why it is always =(0,0)