selecting an iter in a single liststore


I have a problem to select a item in a ListStore when the list is in 'single' or 'browse' mode. When the list is in 'multiple' mode, the problem does not occur. Here is the code:

#!/usr/bin/perl -w

use strict;

use constant  TRUE => 1;
use constant FALSE => 0;

use Gtk2 '-init';
use Carp;

my $win = Gtk2::Window->new('toplevel');

my $dialog = Gtk2::Dialog->new_with_buttons("title",
                                            'gtk-ok' => 'ok',
                                            'gtk-cancel' => 'cancel');
$dialog->set_default_size(300, 500);

my $vbox = $dialog->vbox;

my $ls = Gtk2::ListStore->new('Glib::String');

my $tv = Gtk2::TreeView->new($ls);
$tv->append_column(Gtk2::TreeViewColumn->new_with_attributes('coucou column', Gtk2::CellRendererText->new, 'text', 0));
$vbox->pack_start($tv, TRUE, TRUE, 4);
my $sel = $tv->get_selection;

my $iter;

$iter = $ls->append;
$ls->set($iter, 0, 'one');

$iter = $ls->append;
$ls->set($iter, 0, 'two');

$iter = $ls->append;
$ls->set($iter, 0, 'three');

$iter = $ls->append;
$ls->set($iter, 0, 'four');

my $ret = $dialog->run;


$ret = 'cancel' if $ret eq 'delete-event';
print "$ret\n";

When I run this code, the item selected is 'one', instead of 'three'. If I change the mode to 'multiple', 'three' is selected. If I try to unselect_all before, nothing changes.

        Help !
 -/ O \----------------------------------------
| |/ \|       Alexandre (Midnite) Jousset      |

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]