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

Re: Scrolling to the row in TreeView when selected?



muppet <scott <at> asofyet.org> writes:

> 
> 
> On Sep 13, 2005, at 1:19 AM, Yu Wang wrote:
> 
> > However, if the number of entries is large and the found entry is  
> > in a row not
> > displayed in current ScrolledWindow, i.e could be very buttom or  
> > very top, the
> > window cannot scroll to this entry automatically, once this entry  
> > is selected.
> >
> > Any one has any ideas?
> 
> $treeview->scroll_to_cell ($path, $column=undef, $use_align=FALSE,  
> $row_align=0.0, $col_align=0.0);
> 
> http://developer.gnome.org/doc/API/2.0/gtk/GtkTreeView.html#gtk-tree- 
> view-scroll-to-cell
> 
> For a fully-automatic "always make the selected item visible"  
> behavior, you can connect to the tree's selection's "changed" signal  
> and scroll to the selected path, like this:
> 
> $treeview->get_selection->signal_connect (changed => sub {
>      my ($selection) =  <at> _;
>      my ($model, $iter) = $selection->get_selected;
>      if ($iter) {
>          $selection->get_tree_view->scroll_to_cell ($model->get_path  
> ($iter));
>      }
> });
> 

I tried your code, it gives me:

Gtk-CRITICAL **: gtk_tree_selection_get_selected: assertion `selection->type !=
GTK_SELECTION_MULTIPLE' failed at /home/wangy22/trunk/destcnltr line 670.

I modified it and it works again:

    $treeview->get_selection->signal_connect (changed => sub {
        my ($selection) = @_;
        my $path = $selection->get_selected_rows;
        $selection->get_tree_view->scroll_to_cell ($path) if ($path);
    }); 

Any comments?

Thanks!

Yu




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