2012-12-07 7 views
0

gtk2 perl에서 GUI 응용 프로그램을 작성하고 있습니다. 사용자가 체크 상자를 클릭하면 데이터베이스의 행을 표시하는 테이블이 있습니다. 그리고 다시 클릭하면 정의 된 열 값이있는 행을 숨겨야합니다.GTK2 Perl : 테이블에서 행 제거/숨기기 (TreeViewColumn)

이 코드가 있습니다

# 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); 

을 그리고 체크 박스가 있습니다

$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!!!!! 
    } 
}); 

글쎄, 나는 TreeViewColumn에서 정의 된 $ 성 (상태)에 행을 숨기는 방법 있도록 그들을 숨길을 사용자가 체크 박스를 한 번 더 클릭하면 (비활성화)?

답변

0

이 문제가 해결되었습니다. 이 코드를 사용합니다 :

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 ----------