Forum: Ruby GtkTreeview signal "row-activated"

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Patrick P. (Guest)
on 2006-12-22 16:31
(Received via mailing list)

I have a problem with the TreeView of RubyGTK. Catching the signal works
very well, but I don't know which row of the list was activated :-(.
Does anyone know how to figure out which line was activated?

I've written a litte script to show what I mean. At the moment I do a
'puts "output"', but how could I print the first column of the selected
row? (or anything else)

If these kind of questions are too Gtk specific, please tell me and I
won't bother you with them.


#!/usr/bin/env ruby

require 'gtk2'

def create_list(headline, liststore)
         treeview =
         renderer =
         view =

         headline.each_index do |index|
                 column =[index],
renderer, :text => index)
                 column.resizable = true
                 column.clickable = true
                 column.sort_column_id = index

         return view, treeview, liststore


window =
window.title = "Tattletale"
window.border_width = 10
window.set_size_request(600, 400)
window.add(box =, 0))

view, treeview, liststore = create_list(["Foo", "Bar"],, String))

row = liststore.append
row[0] = "Hello World"
row[1] = "I agree with Hello World"

row = liststore.append
row[0] = "Welcome to Brazil"
row[1] = "Welcome to Denmark"

treeview.signal_connect("row-activated") do |treeview, path, column|
         puts "output"

Olivier (Guest)
on 2006-12-22 18:21
(Received via mailing list)
Le vendredi 22 décembre 2006 15:29, Patrick P. a écrit :
> If these kind of questions are too Gtk specific, please tell me and I
> require 'gtk2'
>                  column.resizable = true
> Gtk::init
> view.show_all
>          puts "output"
> end
> window.show_all
> Gtk::main

You can do all this with the block arguments given :
- "path" tells you which is the activated row
- "treeview" can be asked for the currently selected Iter
(#selection#selected), then you can do whatever you want with it :)

treeview.signal_connect("row-activated") do |treeview, path, column|
  puts path
  i = treeview.selection.selected
  puts "#{i[0]} => #{i[1]}"
Patrick P. (Guest)
on 2006-12-23 13:46
(Received via mailing list)
thanks oliver, that works great :-)

This topic is locked and can not be replied to.