# TreeView and Selection/Selected in Ruby-Gnome2?

**URL:** <https://www.ruby-forum.com/t/treeview-and-selection-selected-in-ruby-gnome2/73868>\
**Category:** Ruby-Gnome 2\
**Created:** [October 27, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/treeview-and-selection-selected-in-ruby-gnome2/73868 "2006-10-27T18:21:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [October 27, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/treeview-and-selection-selected-in-ruby-gnome2/73868/1 "2006-10-27T18:21:59Z")

</div>

Hi,

I am currently trying to implement a simple Midnight-commander  
like ruby-gnome2 Interface. My problem is that I dont seem to be  
able to get the proper selection, i.e. when the user clicks on  
an entry.

However the problem I have seem to be that I do not actually  
get the current selection, but instead the selection before  
the current selection. :\

Is

```
@tree_view.signal_connect('button_press_event') do |widget,event|
  puts "Selection was: "+widget.selection.selected[0]
end

```

a proper way to get the current selection at all?

Here is example code, maybe someone can have a look  
and tell me what is wrong here:

require ‘gtk2’

# SimpleTreeView.new

class SimpleTreeView

# === initialize

def initialize  
@main\_window = Gtk::Window.new  
@main\_window.set\_size\_request 555,255  
create\_parts  
end

def create\_parts  
@renderer=Gtk::CellRendererText.new  
@renderer.set\_property( ‘background’, ‘lavender’ )  
@renderer.set\_property( ‘foreground’, ‘black’ )

```
@list_store = Gtk::ListStore.new(String)
@tree_view = Gtk::TreeView.new(@list_store)
@tree_view_column = Gtk::TreeViewColumn.new('Laaa',
  @renderer, {:text => 0})
@tree_view.append_column(@tree_view_column)

# Example Data:
iter = @list_store.append
iter.set_value(0, 'aaa')
iter = @list_store.append
iter.set_value(0, 'bbb')
iter = @list_store.append
iter.set_value(0, 'ccc')

@tree_view.signal_connect('button_press_event') do |widget,event|
  puts "Selection was: "+widget.selection.selected[0]
end

@main_window.add @tree_view
@main_window.show_all
Gtk.main

```

end  
end  
SimpleTreeView.new

Thanks

–

* * *

Get your free email from [http://www.linuxmail.org](http://www.linuxmail.org)

Powered by Outblaze

* * *

Using Tomcat but need to do more? Need to support web services,  
security?  
Get stuff done quickly with pre-integrated technology to make your job  
easier  
Download IBM WebSphere Application Server v.1.0.1 based on Apache  
Geronimo  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642)

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [October 27, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/treeview-and-selection-selected-in-ruby-gnome2/73868/2 "2006-10-27T19:08:04Z")

</div>

Roebe XXX wrote:

> Is
> 
> ```
> @tree_view.signal_connect('button_press_event') do |widget,event|
> puts "Selection was: "+widget.selection.selected[0]
> end
> 
> ```

how about:  
selection.signal\_connect(‘changed’) do |widget|

Gtk::TreeView.selection is a Gtk::TreeSelection, who has a  
Gtk::TreeSelection::changed signal, that’s what i like to use
