Re: Remove Multiple Rows from Gtk2::ListStore
- From: Zettai Muri <zettaimuri ymail com>
- To: Torsten Schoenfeld <kaffeetisch gmx de>, gtk-perl-list gnome org
- Subject: Re: Remove Multiple Rows from Gtk2::ListStore
- Date: Fri, 18 Dec 2009 18:04:23 -0800 (PST)
That likely happens because by removing rows you made one of the later paths
refer to non-existant rows so that $model->get_iter($path) returns undef. One
quick hack that might make this work is to iterate over the @paths in reverse
order. But to be safe you should follow the doc's advice[1] of converting the
paths to Gtk2::TreeRowReferences (which listen to changes in the model and adapt
accordingly).
Thank you for pointing me towards this. I am using the following code:
my $model = $tv_sources->get_model;
my $selection = $tv_sources->get_selection;
my @paths = $selection->get_selected_rows;
# Convert paths to row references
my @rowrefs;
foreach my $p (@paths)
{
my $treerowreference = Gtk2::TreeRowReference->new ($model, $p);
push (@rowrefs, $treerowreference);
}
# Remove rows based on row references
for (my $i = 0; $i < scalar(@paths); $i++)
{
my $treerowreference = Gtk2::TreeRowReference->new ($model, $paths[$i]);
my $path = $rowrefs[$i]->get_path;
my ($iter) = $model->get_iter($path);
$model->remove($iter);
}
Not sure if it is the "right" way to do it but it works for me.
Was just wondering whether I need to do something like:
$tv_sources->set_model($model);
after the removals are finished Or is this unnecessary because row references are being used?
Thanks again for all the help.
__________________________________________________________________________________
See what's on at the movies in your area. Find out now: http://au.movies.yahoo.com/session-times/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]