Get selected object from TreeView
Posted
by
GoGoDo
on Ask Ubuntu
See other posts from Ask Ubuntu
or by GoGoDo
Published on 2012-10-09T21:15:47Z
Indexed on
2012/10/10
15:54 UTC
Read the original article
Hit count: 213
I've been working on a minor (first time) app with quickly and hit a hurdle - how do I get the selected row (the data) from a TreeView? The data to the TreeView is passed from a list of files in a directory, and I need to know which rows were selected (and thus which files were). What is the best way to do that?
Here's the current code:
self.treeview = self.builder.get_object("treeview")
select = self.treeview.get_selection()
select.connect("changed", self.on_tree_selection_changed)
def on_tree_selection_changed(selection):
model, treeiter = self.treeview.selection-get()
if treeiter != None:
print "You selected", model[treeiter][0]
© Ask Ubuntu or respective owner