Re: Scrolling to the row in TreeView when selected?

On Sep 13, 2005, at 4:42 PM, Yu Wang wrote:

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?

You didn't mention multiple selection; that changes things.  ;-)

get_selected_rows() returns a *list* of paths. You're implicitly taking one of them, apparently the last. This isn't always correct. Say row 17 is already selected, and the user selects 3; since 17 is numerically largest, it is the last value returned by get_selected_rows(), and the view will scroll to row 17.

Another way to do it would be to ignore the selection's "changed" signal, and put the scroll_to_cell() call after the call to select_path(), like this:

  $button->signal_connect (clicked => sub {
my $path = Gtk2::TreePath->new_from_indices ($spinner- >get_value);
      $treeview->get_selection->select_path ($path);
      $treeview->scroll_to_cell ($path);

This has the advantage that the last row selected (by clicking this button) is always visible.

Package contains eight 13-inch aliens in assorted colors.
 -- Catalog copy for space invaders wall decals.

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