Re: How to make listview scroll to active position?



Richard and Jorge,

Many thanks.

It works when adding Richard's code snippet to what I already had, i.e. this:

void listsetsel ( .... int pos , bool isselect )
   {
   ....
   GtkTreeView * tv = ...
   GtkTreeSelection * tsel = gtk_tree_view_get_selection (tv);
   GtkTreeIter iter ;
   GtkListStore * store = (GtkListStore *)gtk_tree_view_get_model ( tv ) ;
   if ( gtk_tree_model_iter_nth_child ( (GtkTreeModel *)store ,
                                        &iter , NULL , pos ) )
      {
      if ( isselect )
         {
         gtk_tree_selection_select_iter ( tsel , &iter ) ;
         }
      else
         {
         gtk_tree_selection_unselect_iter ( tsel , &iter ) ;
         }
      }
   char row [20 ] ;
   sprintf ( row , "%d" , pos ) ;
   GtkTreePath * path = gtk_tree_path_new_from_string ( row ) ;
   gtk_tree_view_scroll_to_cell ( GTK_TREE_VIEW (tv), path, NULL, TRUE,
                                  0.0, 0.0 ) ;
   gtk_tree_view_set_cursor(GTK_TREE_VIEW (tv), path, NULL, FALSE ) ;
   gtk_tree_path_free ( path ) ;
   }








--- On Thu, 22/7/10, Jorge Kalmbach <kalmbach gmail com> wrote:

From: Jorge Kalmbach <kalmbach gmail com>
Subject: Re: How to make listview scroll to active position?
To: "Ken Resander" <kresander yahoo com>
Cc: gtk-list gnome org
Date: Thursday, 22 July, 2010, 12:14 AM



On Wed, Jul 21, 2010 at 12:53 PM, Ken Resander <kresander yahoo com> wrote:
The application uses a listview and works out current position in it, but the list does not scroll to it. The user have to do this manually, which is tedious if the active position is far down the list, say at position 5000.  

I am using the following fragment to set the selection at pos:

[code]
   GtkTreeView * tv = ...
   GtkTreeSelection * tsel = gtk_tree_view_get_selection (tv);
   GtkTreeIter iter ;
   GtkListStore * store = (GtkListStore *)gtk_tree_view_get_model ( tv ) ;
   if ( gtk_tree_model_iter_nth_child ( (GtkTreeModel *)store ,
                                                      &iter , NULL , pos ) )
      {
      gtk_tree_selection_select_iter ( tsel , &iter ) ;
      }
[/code]

How can I make the list scroll to the current selection?


You need to get the path of the selected cell and then use gtk_tree_view_scroll_to_cell

http://library.gnome.org/devel/gtk/stable/GtkTreeView.html#gtk-tree-view-scroll-to-cell

/jk




 
Are there better ways of doing this?



_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





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