Re: Get row text from a treeview



This is how I did it....

gboolean
on_treeview_roster_button_press_event  (GtkWidget       *widget,
                                        GdkEventButton  *event,
                                        gpointer         user_data)
{
  /* Note: Can also use GDK_BUTTON_PRESS, 
   * GDK_2BUTTON_PRESS, GDK_3BUTTON_PRESS
   */
  if(event->type == GDK_2BUTTON_PRESS)
    {
      GtkTreeSelection *selection;
      GtkTreeModel *model;
      GtkTreeIter iter;

      gchar *text = NULL;

      g_print("**** got double click event\n");

      selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
      gtk_tree_selection_set_mode(selection,GTK_SELECTION_SINGLE);
      gtk_tree_selection_get_selected(selection,&model,&iter);
  
      gtk_tree_model_get(model, &iter, 
                         COLUMN_NUMBER, &text,
                         -1);      

      g_print("**** text is '%s'",text);

      if(text != NULL)
        g_free(text);
    }

  return FALSE;
}

BUT - the one thing I did find, is that get selection doesn't work with
GTK_SELECTION_MULTIPLE (i think).  That is why I changed the selection
here...(gtk_tree_selection_set_mode).  I suppose you could set that up
with the GtkTreeView at the start of your application. 

Plus, in case you're wandering... the 'model' is only for the users'
convenience, see the api page:

http://developer.gnome.org/doc/API/2.0/gtk/gtktreeselection.html#gtk-tree-selection-get-selected


Regards,

Martyn

On Fri, 2002-08-09 at 01:12, Magnus-swe wrote:
I solved my problem, i thought i would send the code for it so it can be
found on the internet etc.


// If double clicked, get and show the selected text.
void
on_some_treeview_row_activated     (GtkTreeView     *treeview,
                                    GtkTreePath     *arg1,
                                    GtkTreeViewColumn *arg2,
                                    gpointer         user_data)
{
GtkTreeIter iter;
GtkTreeModel *list_store;
GtkTreeViewColumn *column;
GtkTreePath *path;
gchar *text;

list_store = gtk_tree_view_get_model(GTK_TREE_VIEW(some_treeview));

gtk_tree_view_get_cursor(GTK_TREE_VIEW(some_treeview), &path, &column);

gtk_tree_model_get_iter(list_store, &iter, path);

gtk_tree_model_get(list_store, &iter, 0, &text, -1);

g_print("The text is: %s\n", text);
g_free(text);
gtk_tree_path_free(path);
}

Greetz from: Magnus-swe


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





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