# Tree item context menu 2

**URL:** <https://forum.inductiveautomation.com/t/tree-item-context-menu-2/4818>\
**Category:** Ignition\
**Created:** [July 13, 2012, 9:12pm UTC](https://forum.inductiveautomation.com/t/tree-item-context-menu-2/4818 "2012-07-13T21:12:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvaldi](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cvaldi](https://forum.inductiveautomation.com/u/cvaldi)\
**Post date:** [July 13, 2012, 9:12pm UTC](https://forum.inductiveautomation.com/t/tree-item-context-menu-2/4818/1 "2012-07-13T21:12:12Z")

</div>

I’ve read the thread “tree item context menu” and i found that the solution there only works if the tree view doesn’t have a scroll bar. When the tree view has a scroll bar and it is scrolled the selection is made like it is not scrolled. Is there a way to solve this?  
I’m thinking something like getting the scroll position and then adding it to the position where i will look for the path but i don’t know how to do this.

---

<div class="post-metadata">

**Author:** ![cvaldi](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cvaldi](https://forum.inductiveautomation.com/u/cvaldi)\
**Post date:** [July 13, 2012, 9:45pm UTC](https://forum.inductiveautomation.com/t/tree-item-context-menu-2/4818/2 "2012-07-13T21:45:42Z")

</div>

I’ve solved it by myself with just a call to .getVerticalScrollBar().getValue() to get the scroll position and  
adding this result to y coordinate in getRowForLocation and getPathForLocation  
Here is the final code:

scroll\_position = event.source.getVerticalScrollBar().getValue()  
tree = event.source.getViewport().getView()  
row = tree.getRowForLocation(event.x, event.y+scroll\_position)  
path = tree.getPathForLocation(event.x, event.y+scroll\_position)  
pathStr = “”  
if path != None:  
for item in path.getPath():  
pathStr += str(item) + event.source.separationCharacter  
pathStr = pathStr[1:-1]  
event.source.setSelectedPath(pathStr)
