PHP-GTK
Saturday, December 20, 2014 
download | documentation | applications | faq | changelog | resources 


search for in the  


previousGtkTreeSelection::get_mode
GtkTreeSelection::get_selected_rowsnext

Last updated: Sun, 12 May 2013
view this page in English

GtkTreeSelection::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

<?php
//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);
$view->append_column($col);
 
//add some data to the model/store
$model->append(array('Zero'));
$model->append(array('One'));
$model->append(array('Two'));
 
//add the view to the window
$wnd = new GtkWindow();
$wnd->set_title('GtkTreeView selection example');
$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));
$wnd->add($view);
$wnd->show_all();
Gtk::main();
?>

See also: get_selected_rows()


User Contributed Notes
gtk.gtktreeselection.method.get_selected.php
add a note about notes
There are no user contributed notes for this page.


previousGtkTreeSelection::get_mode
GtkTreeSelection::get_selected_rowsnext

Last updated: Sun, 12 May 2013
view this page in English


credits 

PHP  Copyright © 2001-2014 The PHP Group
 All rights reserved.
Last updated: Sun May 12 20:51:01 2013 CEST