array get_selected();

Returns an array containing the model and the iterator of the currently selected row.

This method works only, if the selection mode is set to Gtk::SELECTION_SINGLE or Gtk::SELECTION_BROWSE. For other modes, retrieve the selection with get_selected_rows() .

Example 128. Using get_selected

//create a model
$model = new GtkListStore(Gobject::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();
//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 the selected row.
function selection_changed($selection)
    //get_selected returns the store and the iterator for that row
    list($model, $iter) = $selection->get_selected();
    //get one single value of the model via get_value
    echo 'Value of column 0: ' . $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

//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_rows()