selecting an iter in a single liststore
- From: Alexandre Jousset <mid gtmp org>
- To: gtk-perl-list gnome org
- Subject: selecting an iter in a single liststore
- Date: Fri, 17 Sep 2004 13:04:35 +0200
Hello,
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');
$win->show;
my $dialog = Gtk2::Dialog->new_with_buttons("title",
$win,
'modal',
'gtk-ok' => 'ok',
'gtk-cancel' => 'cancel');
$dialog->set_default_size(300, 500);
$dialog->set_position('mouse');
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));
$tv->set_headers_visible(0);
$tv->show;
$vbox->pack_start($tv, TRUE, TRUE, 4);
my $sel = $tv->get_selection;
$sel->set_mode('single');
#$sel->set_mode('multiple');
#$sel->unselect_all;
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');
$sel->select_iter($iter);
$iter = $ls->append;
$ls->set($iter, 0, 'four');
my $ret = $dialog->run;
$dialog->hide;
$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]