Monday, October 27, 2014

Right-Click on TreeView

I created last time a "My Favorite" popup menu for my ERP app.  This allows my users to easily jump from one module to another without the need to close what they are working on.  The hotkey is F5.   Each of my users have their own My Favorite as well so they can control themselves what they wanted to be there (those modules they have access to).



I used Ctrl+F to add or remove items on the Favorite Menu utilizing the Selected/Highlighted node from the ActiveX TreeView Control (MSComctlLib.TreeCtrl.2) as when I look for a right-click event back then, I cannot find one.  And I do not want to waste my time on finding that missing Right-Click event as all I wanted is a quick fix for my need.



However, said approach lacks appeal so I said to myself today as I am a bit free to do an experiment, I will try to make that Right-Click function.  And it appears it is very easy enough to achieve that.  The right-click can be done on MouseDown event using the first parameter button.

When you left click on the treeview, the button parameter receives a value of 1 and when your right-click, it receives 2, while a click on the mouse scroll wheel triggers a value of 4. So a simple IF condition was able to produce what I need with something like this:

MouseDown Event
*** ActiveX Control Event ***
LPARAMETERS button, shift, x, y
IF button = 2
   PopFave(this.selectedItem.Text)
ENDIF




And there you have it, just in case you are wondering how to trigger a right-click as well on your treeview control.  Cheers!


No comments:

Post a Comment