[Glade-users] Re: single click treeview selection question (Kim Adil)



I am trying to print the value selected in a treeview after the user
single clicks a row in a treeview. unfortunately the:

          if (gtk_tree_model_get_iter(model, &iter, path))

line in my code below always is false, even though there is a row
selected. How can I return the selected row on a single click?

The treeview's are confusing as heck- I miss the good old clists of old...
There's a great tutorial on treeview's at
http://scentric.net/tutorial/treeview-tutorial.html

Are you enabling a callback for the click? It should look something like:
(see how many mistakes I made...)

/////////////////////////////////////////////////////////////////
// Callback for when a selection is made in a TreeView widget:
gboolean
view_selection_func (GtkTreeSelection *selection,
                     GtkTreeModel     *model,
                     GtkTreePath      *path,
                     gboolean          path_currently_selected,
                     gpointer          userdata)
{
  GtkTreeIter iter;
  int index;

  if (gtk_tree_model_get_iter(model, &iter, path))
  {
    // Index of the row that is being selected/deselected
    index = (gtk_tree_path_get_indices(path))[0]; // or maybe you dont care
about the int index??
// you could also get the text instead...
  }

  return TRUE; /* allow selection state to change */

}

//////////////////////
int main()
{

  // ...... your init stuff here .......


  GtkWidget         * myView;
  myView = (GtkWidget*)glade_xml_get_widget(toplevel_xml,
                                             "YOUR_TREEVIEW_WIDGET_NAME");

  // Each time a selection is made, call 'view_selection_func' function

gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_VIEW(myView)),
                                         view_selection_func,

"SOME_TEXT_IF_YOU_WANT_TO_PASS_IT",
                                         NULL);

/////////////////////////////////

Hope that helps...

Joel Wheeler




                                                                           
             glade-users-reque                                             
             st@lists.ximian.c                                             
             om                                                         To 
             Sent by:                  glade-users lists ximian com        
             glade-users-bounc                                          cc 
             es@lists.ximian.c                                             
             om                                                    Subject 
                                       Glade-users Digest, Vol 4, Issue 18 
                                                                           
             08/25/2005 12:00                                              
             PM                                                            
                                                                           
                                                                           
             Please respond to                                             
                glade-users                                                
                                                                           
                                                                           




Send Glade-users mailing list submissions to
             glade-users lists ximian com

To subscribe or unsubscribe via the World Wide Web, visit
             http://lists.ximian.com/mailman/listinfo/glade-users
or, via email, send a message with subject or body 'help' to
             glade-users-request lists ximian com

You can reach the person managing the list at
             glade-users-owner lists ximian com

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Glade-users digest..."


Today's Topics:

   1. single click treeview selection question (Kim Adil)


----------------------------------------------------------------------

Message: 1
Date: Thu, 25 Aug 2005 21:30:36 +1000
From: Kim Adil <ksadil bigpond net au>
Subject: [Glade-users] single click treeview selection question
To: glade-users lists ximian com
Message-ID: <1124969436.8422.7.camel@localhost.localdomain>
Content-Type: text/plain

Hello,

I am trying to print the value selected in a treeview after the user
single clicks a row in a treeview. unfortunately the:

             if (gtk_tree_model_get_iter(model, &iter, path))

line in my code below always is false, even though there is a row
selected. How can I return the selected row on a single click?

(PS I am able to do this for a double click event, single click alludes
me)

thanks,
Kim




gboolean on_treeview1_button_release_event(GtkTreeView        *treeview,
                       GtkTreePath        *path,
                       GtkTreeViewColumn  *col,
                       gpointer            userdata)
  {
    GtkTreeModel *model;
    GtkTreeIter   iter;

    g_print ("A row has been clicked!\n");

    model = gtk_tree_view_get_model(treeview);

    if (gtk_tree_model_get_iter(model, &iter, path))
    {
       gchar *name;

       gtk_tree_model_get(model, &iter, COL_A, &name, -1);

       g_print ("Single clicked row contains name %s\n", name);

       g_free(name);
    } else {
                         printf("\n no tree model");
             }
             return TRUE;
  }



------------------------------

_______________________________________________
Glade-users mailing list
Glade-users lists ximian com
http://lists.ximian.com/mailman/listinfo/glade-users


End of Glade-users Digest, Vol 4, Issue 18
******************************************





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