Re: Combobox (set active and retrieve data)
| From: | Jake Cobb | Date: | Tue, 21 Aug 2007 19:46:35 +0000 |
| Subject: | Re: Combobox (set active and retrieve data) | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-8052@lists.php.net to get a copy of this message | ||
Hello,
To store the index you should keep a second column in your model. So, create your model this way:
$modelo2 = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_LONG);
And add your data this way:
foreach($aProveedor as $index => $proveedor)
{
$modelo2->append(array($proveedor, $index));
}
Then you can loop over the model to find the row with the desired index and set it active, assuming the index you want to activate by is in $desired_index:
foreach($modelo2 as $row)
{
if($row[1] == $desired_index)
{
$cajasCampos[$fila]->set_active_iter($row->iter);
break;
}
}
You can retrieve your data in a similar loop, $row[0] will be the text and $row[1] will be the integer.
-Jake Cobb
Robertico wrote:
Hi . I have an array with pair values $aProveedor = array(04=>"Nacional",05=>"Extranjero",06=>"Global"); And hace this code. $cajasCampos[$fila] = new GtkComboBox(); $modelo2 = new GtkListStore(Gtk::TYPE_STRING); $cajasCampos[$fila]->set_model($modelo2); $cellRenderer = new GtkCellRendererText(); $cajasCampos[$fila]->pack_start($cellRenderer); $cajasCampos[$fila]->set_attributes($cellRenderer, 'text', 0); foreach($aProveedor as $proveedor) {$modelo2->append(array($proveedor));} $cajasCampos[$fila]->set_active(0); //(1) --> How can I set active by index? I mean set_active(04) | set_active(05) | set_active(06) (2) I need the combo shows the Text Values (Nacional, Extranjero, Global), but when I retrieve date value I need to get the numeric values (04,05,06) How can I do that? Thanks in advance!!