Re: [PHP-GTK] Combobox (set active and retrieve data)

[email protected] (Jake Cobb)
Newsgroups php.gtk.general
Message-ID <[email protected]>
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!!
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.