When the user clicks on the list, I only want to know which row has been selected.

The code you posted runs fine here, so I don't know what your problem is. The following shows how to do row selection.

#!/usr/bin/perl -w use Data::Dumper; use Gtk2 -init; use Gtk2::Ex::Simple::List; my $win = Gtk2::Window->new; $win->set_title ('Gtk2::Ex::Simple::List exapmle'); $win->set_border_width (6); $win->set_default_size (500, 300); $win->signal_connect (delete_event => sub { Gtk2->main_quit; }); my $hbox = Gtk2::HBox->new (0, 6); $win->add ($hbox); my $scwin = Gtk2::ScrolledWindow->new; $hbox->pack_start ($scwin, 1, 1, 0); $scwin->set_policy (qw/automatic automatic/); my $slist = Gtk2::Ex::Simple::List->new ( 'Name' => 'text', ); $slist->get_selection->set_mode ('multiple'); @{$slist->{data}} = ('a'..'z'); $scwin->add ($slist); my $vbox = Gtk2::VBox->new (0, 6); $hbox->pack_start($vbox, 0, 1, 0); my $button = Gtk2::Button -> new('What\'s Selected by indices?'); $button -> signal_connect(clicked => \&report_indices, $window); # pack quit button into $main_vbox $vbox -> pack_start($button, 0, 1, 0); my $button1 = Gtk2::Button -> new('What\'s Selected by value?'); $button1 -> signal_connect(clicked => \&report_items, $window); # pack quit button into $main_vbox $vbox -> pack_start($button1, 0, 1, 0); my $button2 = Gtk2::Button -> new('Delete a value(s)'); $button2 -> signal_connect(clicked => \&del_items, $window); # pack quit button into $main_vbox $vbox -> pack_start($button2, 0, 1, 0); my $button3 = Gtk2::Button -> new('Insert values at pos 2'); $button3 -> signal_connect(clicked => \&add_items, $window); # pack quit button into $main_vbox $vbox -> pack_start($button3, 0, 1, 0); my $button4 = Gtk2::Button -> new('Overwrite values at pos 2'); $button4 -> signal_connect(clicked => \&rpl_items, $window); # pack quit button into $main_vbox $vbox -> pack_start($button4, 0, 1, 0); # finally, a button to end it all $btn = Gtk2::Button->new_from_stock ('gtk-quit'); $btn->signal_connect (clicked => sub { Gtk2->main_quit; }); $vbox->pack_end($btn, 0, 1, 0); $win->show_all; Gtk2->main; sub del_items { my @indices = $slist -> get_selected_indices; #need to sort numerically, and splice off the highest numbers first + foreach my $i (reverse sort {$a<=>$b} @indices ) { print "$i\n"; splice @{ $slist->{data} }, $i, 1; } } sub add_items { my @new; for(1..5){push @new,int rand 100} # adds 5 elements at pos 2, shifting others over + splice @{ $slist->{data} }, 2, 0, @new; } sub rpl_items { my @new; for(1..5){push @new,int rand 100} # adds 5 elements at pos 2, removing previous items + splice @{ $slist->{data} }, 2, 5, @new; } sub report_indices { my @indices = $slist -> get_selected_indices; foreach my $i (@indices) { print $i . "\n"; # I'd rather print the actual data here. } } sub report_items { my @indices = $slist -> get_selected_indices; foreach my $i (@indices) { print $slist->{data}[$i][0] . ' '; } print "\n"; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Can't locate object method "get_row_data_from_path" via package "Gtk2::Ex::Simple::List" by zentara
in thread Can't locate object method "get_row_data_from_path" via package "Gtk2::Ex::Simple::List" by aslewis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.