array get_selected_rows();

Returns an array containing the model and an array of tree paths of the selected rows. The tree path array can be walked by an foreach or for loop, and the single paths can be converted to an iterator via the get_iter() method of GtkTreeModel.

Unlike the get_selected() method, this here works with all selection modes.

Example 129. Using get_selected_rows

//create a model
$model = new GtkListStore(Gtk::TYPE_STRING);
//create the view to display the model data
$view = new GtkTreeView($model);

//now, get the selection object of that view
$selection = $view->get_selection();

//we want to be able to select multiple rows

//capture the "changed" signal
$selection->connect('changed', 'selection_changed');

*   This is the callback function for the changed
*   signal and display the value of the first column
*   of all selected rows
function selection_changed($selection)
    list($model, $arPaths) = $selection->get_selected_rows();
    echo "Selection is now:\r\n";
    foreach ($arPaths as $path) {
        $iter = $model->get_iter($path);
        echo '  ' . $model->get_value($iter, 0) . "\r\n";
}//function selection_changed($selection)

//add a column to display the data
$col = new GtkTreeViewColumn('Number', new GtkCellRendererText(), 'text', 0);

//add some data to the model/store

$selection->select_range(1, -1);

//add the view to the window
$wnd = new GtkWindow();
$wnd->set_title('GtkTreeView selection example');
$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));

See also: get_selected() count_selected_rows()