# FXRuby, FXTreeList

**URL:** <https://www.ruby-forum.com/t/fxruby-fxtreelist/48046>\
**Category:** Ruby\
**Created:** [November 16, 2005, 7:40am UTC](https://www.ruby-forum.com/t/fxruby-fxtreelist/48046 "2005-11-16T07:40:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fleck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@Fleck](https://www.ruby-forum.com/u/Fleck)\
**Post date:** [November 16, 2005, 7:40am UTC](https://www.ruby-forum.com/t/fxruby-fxtreelist/48046/1 "2005-11-16T07:40:21Z")

</div>

Hi,  
I’ ve created a TreeList that shows the files in a directory. How can I  
create a context menu that pops up, when I right-click on a selected  
item? I know how to create the popup menu, but how can I prevent it to  
get shown when I click somewhere else than the item? Do I have to  
remember the items I selected and then check if it’ s under the cursor  
when right-clicking?

Thanks,  
Alexander F…

---

<div class="post-metadata">

**Author:** ![Fleck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@Fleck](https://www.ruby-forum.com/u/Fleck)\
**Post date:** [November 16, 2005, 6:09pm UTC](https://www.ruby-forum.com/t/fxruby-fxtreelist/48046/2 "2005-11-16T18:09:00Z")

</div>

On 11/16/05, Alexander F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ ve created a TreeList that shows the files in a directory. How can I create a context menu that pops up, when I right-click on a selected item? I know how to create the popup menu, but how can I prevent it to get shown when I click somewhere else than the item? Do I have to remember the items I selected and then check if it’ s under the cursor when right-clicking?

I think that I’d just call FXTreeList#getItemAt(event.win\_x,  
event.win\_y) to determine which item was right-clicked. If the user  
right-clicked somewhere outside of an item, getItemAt() ought to  
return nil.

---

<div class="post-metadata">

**Author:** ![Fleck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@Fleck](https://www.ruby-forum.com/u/Fleck)\
**Post date:** [November 17, 2005, 9:08am UTC](https://www.ruby-forum.com/t/fxruby-fxtreelist/48046/3 "2005-11-17T09:08:00Z")

</div>

Thanks,  
it works, after a while of trying and modifying. I’ m on my way into the  
FXRuby library and still have some newbie problems with the events and  
their handling. But I’ m going to manage that.  
Thanks,  
Alex.

---

<div class="post-metadata">

**Author:** ![Fleck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@Fleck](https://www.ruby-forum.com/u/Fleck)\
**Post date:** [November 17, 2005, 11:44am UTC](https://www.ruby-forum.com/t/fxruby-fxtreelist/48046/4 "2005-11-17T11:44:54Z")

</div>

Hi,  
but now another question:  
When I selected an item, all works fine, but the menu always pops up,  
when I right-clicked in the item’ s row. That doesn’ t happen above or  
below the row. What happens here?

Thanks,  
Alex.
