Re: data from tree




 JS> >  J> Does anybody know, how I can get data from selected row in Tree? I
 JS> >  J> have signal handled but I need to know what I selected.
 JS> > 
 JS> > I did this once.  I'm not sure this is the right way of doing it though.

 JS> > GtkWidget *
 JS> > get_selection (GtkTree *tree)
 JS> > {
 JS> >   Glist *selection = GTK_TREE_SELECTION (tree);
 JS> >   return selection ? GTK_WIDGET (selection->data) : NULL;
 JS> > }

 JS> But selection->data doesn't contain any string which I want. There are
 JS> only random characters.

selection->data should contain a widget, the tree item, as I
understand it.  Not the text.  Before inserting the tree item I did
something like:

    item = gtk_tree_item_new_with_label (name);
    gtk_widget_show (item);
    gtk_object_set_user_data (GTK_OBJECT (item), foo_data);
    gtk_tree_append (tree, item);

foo_data is now associated with the tree item, and can be extracted
with gtk_object_get_user_data (GTK_OBJECT (item));

 JS> > selected = main_window_tree_selected(main_window_data);
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
/main_window_tree_selected(main_window_data)/get_selection (tree)/s

 JS> > if (selected) { 
 JS> >   data = gtk_object_get_user_data(GTK_OBJECT (selected));
 JS> > }

 JS> I don't understand. Is it part of main program? What has it to do? I have
 JS> no function named main_window_tree_selected... 

Sorry. main_window_tree_selected should have been get_selection
(foo_tree). I cut the source from a file, and only renamed the
function one place :{

 JS> I tried *_get_user_data in callback function but it also doesn't work :-(.
 JS> Do you have any idea what to do?

No...this worked for me...unless it's the label text you want to
extract and not user_data associated with the tree item.

I don't know how to do that directly in the tree widget.  In ctree you
would call gtk_ctree_get_text (ctree, node, column, &text).

If you could get to the label in the tree you could call

 gtk_label_get (label, &text);

but I don't know how to get the label from the tree item. Does anyone
have an idear?  I would also like to know.

I don't know if any of this helps...

/mailund



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