Re: Get all rows in Gtk2::ListStore



2009/8/18 Kevin Ryde <user42 zip com au>:
Peter E Dennis <peter edwin dennis gmail com> writes:

get all of the second column's values:

I made a column_contents() in my Gtk2::Ex::TreeModelBits based on
$model->foreach per below.  A loop with your own iters ought to work
equally well.

while ( $list_store->iter_next($iter) )

Is that the right loop condition?  It doesn't miss the last row does it?

Probably not.  I really had no idea what I was doing.


sub column_contents {
 my ($model, $column) = @_;
 my @ret;

 # pre-extend, helpful for a list model style, likely to do little for an
 # actual tree
 $#ret = $model->iter_n_children(undef) - 1;

 my $pos = 0;
 $model->foreach (sub {
                    my ($model, $path, $iter) = @_;
                    $ret[$pos++] = $model->get_value ($iter, $column);
                    return 0; # keep walking
                  });
 $#ret = $pos-1;
 return @ret;
}


Thank you very much for providing an example.  I will give it a go at
applying it my own program.



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