PHP-GTK
Thursday, October 30, 2014 
download | documentation | applications | faq | changelog | resources 


search for in the  


previousGtkTreeView::get_search_column
GtkTreeView::get_vadjustmentnext

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

GtkTreeView::get_selection

GtkTreeSelection get_selection();

This method returns the GtkTreeSelection object associated with the view. The selection object itself contains all the data about a selection, be it just a single row, or multiple rows that are selected.

Always keep in mind that the view, not the underlying model, has a selection! That means that different views of the same model can have different selections.

Example 141. Using GtkTreeSelection

<?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();
?>

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


previousGtkTreeView::get_search_column
GtkTreeView::get_vadjustmentnext

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