Re: Get all rows in Gtk2::ListStore

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?

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;

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