Basically, you have to use GtkTreeView and set its "model" property to a GtkListStore that contains your data. GtkTreeView manages selection with GtkTreeSelection class. Use gtk_tree_view_get_selection (or whatever it is mapped to in ruby-gtk) to get the GtkTreeSelection. And set the selection mode to "multiple".
Here's an example in Python. In Ruby/Gtk it should be similar.
import pygtk
pygtk.require('2.0')
import gtk
import gobject
w = gtk.Window()
w.connect('destroy', lambda w:gtk.main_quit())
l = gtk.ListStore(gobject.TYPE_STRING)
l.append(('Vinz',))
l.append(('Jhen',))
l.append(('Chris',))
l.append(('Shynne',))
treeview = gtk.TreeView()
treeview.set_model(l)
column = gtk.TreeViewColumn()
cell = gtk.CellRendererText()
column.pack_start(cell)
column.add_attribute(cell,'text',0)
treeview.append_column(column)
treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
def print_selected(treeselection):
(model,pathlist)=treeselection.get_selected_rows()
print pathlist
treeview.get_selection().connect('changed',lambda s: print_selected(s))
w.add(treeview)
w.show_all()
gtk.main()
dmitry_vk
2009-07-31 04:43:38