Of course AFAIK, there is no documentation as of yet for Gtk3-Perl, and I could be using some incorrect code, but I truly feel that there's a bug in the Gtk3 code that is doing this.
I've been a bit longwinded, but, to summarize, when $dlg is run the first time, the tree view displays the data, but on a second pass, after dlear() ing, nothing (except for the column headers) is shown.
sub select_cust_from_ids {
my $ids = shift; # A list of ID's to search for in the database
# 'dlg_customer_view_multi' is a dialog defined in the glade file. it is a dialog
# containing a treeview with its ListStore Model and its columns defined also in
# the glade file.
my $dlg = $builder->get_object ('dlg_customer_view_multi');
my $view = $builder->get_object ('treeview_customer_data');
# First build a list of placeholders for the query
my @placeholders;
foreach (@$ids) {
push @placeholders, 'cust_id = ?';
}
my $qry = qq/SELECT lastname,firstname,coalesce(mi,''),streetaddr,/ .
qq/city,state,zip,cust_id FROM poolsalesfullview WHERE / .
join (' OR ', @placeholders);
my $custs = $dbh->selectall_arrayref ($qry, undef, @$ids);
unless ($custs) {
my $msg = 'No data was retrieved...';
if ($dbh->err) {
$msg .= "\n" . $dbh->errstr;
}
my $d = Gtk3::MessageDialog->new ($w_main, 'destroy-with-parent',
'notice', 'gtk-ok', $msg);
$d->run;
$d->destroy;
return;
}
my $m = $view->get_model;
$m->clear;
foreach my $row (@$custs) {
my $iter = $view->get_model->append();
unless ($view->get_model->iter_is_valid($iter)) {
my $d = MessageDialog->new ($dlg, 'destroy-with-parent',
: 'warning', 'gtk-close',
'Invalid iter for TreeView');
return;
}
my (@cols, @vals);
my @parms = ($iter);
for (my $x = 0; $x < scalar (@$row); $x++) {
#push(@cols, $x); push (@vals, $row->[$x]);
push (@parms, $x => $row->[$x]);
}
#$view->get_model->set ($iter, \@cols, \@vals);
$view->get_model->set(@parms);
}
# ------ Testing ------
# this displays the correct data in the second pass
# so it appears that the Liststore itself is being populated correctly
# it seems that somehow, the treeview is losing its relation to the Model
# when the ListStore is clear()-ed when data is in it.
# my $it = $view->get_model->get_iter_first;
#
# while ($it) {
# my ($l,$f);
# $l = $view->get_model->get_value($it, 0);
# $f = $view->get_model->get_value($it, 1);
# print "$f $l\n";
#
# unless ($view->get_model->iter_next($it)) {
# $it = undef;
# }
# } print "\n";
# ------ Testing ------
$dlg->run;
$dlg->hide;
}