AkisC
AkisC

Reputation: 827

C++ Builder 6 Different Popup menu on Items and Subitems of a TreeView and No Popup on empty area

I want to have different popup menu on Items and SubItems and NO Popup menu on empty area of a TTreeView is that possible ?

I want something like the pictures bellow

enter image description here

enter image description here

enter image description here

Upvotes: 2

Views: 1772

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 598134

There are two ways you can do that.

  1. Create 2 separate TPopupMenu objects with the desired menu items, do not assign either one of them to the TreeView's PopupMenu property, and then use the TreeView's OnContextMenu event to call the Popup() method of whichever TPopupMenu you need based on which node the user is clicking on.

  2. Create 1 TPopupMenu object and put both menu items in it, and assign it to the TreeView's PopupMenu property, then use the TPopupMenu.OnPopup event to show/hide the menu items based on which node the user is clicking on.

In either case, you can use the TTreeView.GetNodeAt() method to determine which node is located at the coordinates of a mouse click, if any.

Upvotes: 3

Related Questions