# GtkTreeview signal "row-activated"

**URL:** <https://www.ruby-forum.com/t/gtktreeview-signal-row-activated/80229>\
**Category:** Ruby\
**Created:** [December 22, 2006, 3:31pm UTC](https://www.ruby-forum.com/t/gtktreeview-signal-row-activated/80229 "2006-12-22T15:31:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjpatten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@pjpatten](https://www.ruby-forum.com/u/pjpatten)\
**Post date:** [December 22, 2006, 3:31pm UTC](https://www.ruby-forum.com/t/gtktreeview-signal-row-activated/80229/1 "2006-12-22T15:31:39Z")

</div>

Hello,

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.

Thanks,  
Patrick

#!/usr/bin/env ruby

require ‘gtk2’

def create\_list(headline, liststore)  
treeview = Gtk::TreeView.new(liststore)  
renderer = Gtk::CellRendererText.new  
view = Gtk::ScrolledWindow.new.add(treeview)

```
     headline.each_index do |index|
             column = Gtk::TreeViewColumn.new(headline[index],

```

renderer, :text =\> index)  
column.resizable = true  
column.clickable = true  
column.sort\_column\_id = index  
treeview.append\_column(column)  
end

```
     return view, treeview, liststore

```

end

Gtk::init

window = Gtk::Window.new  
window.title = “Tattletale”  
window.border\_width = 10  
window.set\_size\_request(600, 400)  
window.add(box = Gtk::VBox.new(false, 0))

view, treeview, liststore = create\_list([“Foo”, “Bar”],  
Gtk::ListStore.new(String, String))  
box.pack\_start(view)  
view.show\_all

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”  
end

window.show\_all  
Gtk::main

---

<div class="post-metadata">

**Author:** ![pjpatten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@pjpatten](https://www.ruby-forum.com/u/pjpatten)\
**Post date:** [December 22, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/gtktreeview-signal-row-activated/80229/2 "2006-12-22T17:21:51Z")

</div>

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]}”  
end

---

<div class="post-metadata">

**Author:** ![pjpatten](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@pjpatten](https://www.ruby-forum.com/u/pjpatten)\
**Post date:** [December 23, 2006, 12:46pm UTC](https://www.ruby-forum.com/t/gtktreeview-signal-row-activated/80229/3 "2006-12-23T12:46:45Z")

</div>

thanks oliver, that works great 🙂

cu  
pp
