Re: treeview clearing

On Tue, 21 Mar 2006 17:48:40 +0100 (CET)
Szabó Géza <szgezu freemail hu> wrote:

and I just want to simply clear all the whole treeview.
I tried with $treestore->clear; but nothing happens.
How can this be fixed?

Your $treestore may be out of scope? Do you have warnings and
strict enabled? This works.

#! /usr/bin/perl -w
use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/; 
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });

my $vbox = &ret_vbox();

sub ret_vbox {
   my $vbox = Gtk2::VBox->new(FALSE,5);
   my $sw = Gtk2::ScrolledWindow->new (undef, undef);
                $sw->set_shadow_type ('etched-out');
                $sw->set_policy ('automatic', 'automatic');
                $sw->set_size_request (300, 300);
        my $tree_store = Gtk2::TreeStore->new(qw/Glib::String/);

        foreach (1..30) {
                my $parent_nr = $_;
                my $iter = $tree_store->append(undef);
                $tree_store->set ($iter,0 => "Parent $parent_nr");
                 foreach (1..3){
                  my $iter_child = $tree_store->append($iter);
                      $tree_store->set ($iter_child,0 => "Child $_ of Parent $parent_nr");

        my $tree_view = Gtk2::TreeView->new($tree_store);
        my $tree_column = Gtk2::TreeViewColumn->new();
        $tree_column->set_title ("Click to sort");
        my $renderer = Gtk2::CellRendererText->new;
        $tree_column->pack_start ($renderer, FALSE);
        $tree_column->add_attribute($renderer, text => 0);
        $tree_view->append_column ($tree_column);

    my $button = Gtk2::Button->new('Clear');
    $vbox->pack_end( $button, FALSE, FALSE, 0 );
    $button->signal_connect( clicked => sub{
                      } );

return $vbox;

I'm not really a human, but I play one on earth.

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