Frage

I'm writing a GUI app on gtk2 perl. There is a table which show rows from database, when an user click on a checkbox. And when he click on it again then rows with defined column value must be hidden.

I have this code:

# ListStore to stores model
my $list_store = Gtk2::ListStore->new(("Glib::String") x 3);

my $rows = &get_row($st); # arrayref on rows from a db

sub set_columns {
    my ($store, $rows) = @_;

    foreach my $row (@$rows) {
        my ($num, $name, $status) = @$row;
        $store->set($store->append,
            0 => $num,
            1 => $name,
            2 => $status,
        );
    }
}   # ----------  end of subroutine set_columns  ----------

...

sub show_columns {
    my ($names) = @_;                        # reference to @name_columns
    my $i = 0;                               # number of columns within ListStore
    foreach (@$names) {
        # TreeViewColumn is a column for TreeView
        my $col = Gtk2::TreeViewColumn->new;
        $col->set_title($_);
            $col->set_alignment(0.5);            # alignment of header
            $col->set_clickable(1);              # can click on header


        $tree_view->append_column($col);

        my $rend = Gtk2::CellRendererText->new;
        $col->pack_start($rend, TRUE);

        # Link column of TreeViewColumn's renderer to column of ListStore
        $col->add_attribute($rend, 'text', $i++);
    }
}

...

my @name_columns = qw(№ Name Status);

&set_columns($store, $rows);
&show_columns(\@name_columns);

And I have a checkbox:

$ch->signal_connect(toggled => sub {
    my $self = shift;
    if ($self->get_active) {
        print "Yes\n";
                my $st = 'Good';       # status 
        &global_view($list_store, $st);  # function which call set and show_columns
    } else { 
        print "No\n";
                # TO-DO here!!!!!
    }
});

Well, how can I hide rows with defined $st(status) from TreeViewColumn so as to hide them from users when they click on the checkbox one more time(deactivate)?

War es hilfreich?

Lösung

I've solved this problem! I use this code:

sub remove_item {
    my ($st)= @_;
    my $it = $list_store->get_iter_first;
    while ($it) {
        if ($list_store->iter_is_valid($it) && $list_store->get($it, 3) eq $st) {
            my $tmp = $it;  # temporary iter for row delete
            print "Good\n";
            $it = $list_store->iter_next($it);
            $list_store->remove($tmp);
        } else {
            print "Bad\n";          
            $it = $list_store->iter_next($it);      
        }
    }   

}   # ----------  end of subroutine remove_item  ----------
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top