RE: Getting text from a treeview...



Ok. :D

What i want is the way to get all items selected (in a string) from
a GtkTreeSelection * on a multiselectable treeview...

This is how I do it:

        GtkTreeSelection *selection = NULL;
        GtkTreeIter iter;

        gint count = 0;
        gint i = 0;
        
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mytreeview));
        if(selection == NULL) 
                return;

        count = gtk_tree_model_iter_n_children((GTK_TREE_VIEW(mytreeview),
NULL);

        for(i=0;i<count;i++)
        {
                gchar *path_str = g_strdup_printf("%d", i);
                        
                if(path_str == NULL) 
                        continue;
                
        
if(gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(mymodel), &iter,
(const gchar*)path_str) == FALSE)
                {
                        g_free(path_str);
                        continue;
                }

        
if(gtk_tree_selection_iter_is_selected(GTK_TREE_SELECTION(selection), &iter)
== TRUE)
                {
                        /* 
                                do something with selected row ... 
                                at this to a list of integers ?
                        */
                }

                g_free(path_str);
        }

There is probably a better way of doing it, I think there is from some of
the new API in 2.2.x atleast - but this method should work.  In fact, this
is the same as calling the new API 2.2 call
gtk_tree_selection_get_selected_rows().
http://developer.gnome.org/doc/API/2.0/gtk/GtkTreeSelection.html#gtk-tree-se
lection-selected-foreach

Or I suppose you could call a function on EACH selected item... and collate
your list that way? (using gtk_tree_selection_selected_foreach()).

Regards,
Martyn          



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