Andrew,

I reviewed the code you supplied.  The gtk_tree_model_get() have the
correct column numbers, so the fact that PART_COLUMN_CLASS is changing
is interesting from a gcc compiler option perspective; but not cause for
the problems you are experiencing.

PART_COLUMN_CLASS should be a fixed enum value, and any changes to its
value are likely to be caused by optimizing compiler options - not
runtime issues. What are your compiler options; "-Wall -g -ansi -O2",
where -oh two(not zero two) is significant.  I'm going to ignore that
this number is changing - as its ability to change would cause chaos for
all of gtk which makes extensive use of enums.

Most likely cause of the behavior you describe!.  The *iter value is not
set to the currently selected row.  I.E no selection mechanisum being
used, or used incorrectly.

CODE EXAMPLE:

/* at the end of the treeview create routine */
...
GtkTreeSelection *part_select = NULL;
part_select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
gtk_tree_selection_set_mode (part_select, GTK_SELECTION_SINGLE);
g_object_set_data (G_OBJECT (treeview), "selection-pointer", (gpointer) 
part_select);
...

/* 
 * in the supplied routine -- validate the selection first, 
 * then get/set data as originally shown 
*/
GtkTreeSelection *part_select = NULL;
GtkTreeIter iter;            /* will get set to the selection */

part_select = (GtkTreeSelection *)g_object_get_data (G_OBJECT(treeview),
"selection-pointer");

if (gtk_tree_selection_get_selected (prod_select, NULL, &iter))
{
    gtk_tree_model_get (model, &iter...);   /* NOTICE SYNTAX OF iter --> & */
    /* -- set data */
}
else
{
   /* nothing selected */

}
 
END CODE EXAMPLE:

Maybe this is what was calling your original routine, I don't know.
These are tips, research and adapt to your program as needed.  The
thinking is to set treeview for single selection, and when selected get
the selected iter, then get the data.  Getting the selected iter ensure
you get the correct one each time.

g_object_get_data/g_object_set_data() are example ways of storing values
in the common object, so your routines don't need such a long parm list.

James,




On Sat, 2008-05-10 at 19:34 -0400, Andrew Rowland wrote:
> All,
> 
> I'm not sure what I'm doing wrong.  When I select a row in a treeview,
> the values of the columns are read and used to populate various entries
> and combos.  The thing that I can't figure out is that the value of one
> column is being changed to the value of another column.
> 
> Below is a snippet of the function (ANNOTATED IN CAPS) wherein the
> column value is changing.  Running my app in gdb, I've been able to
> figure out where the change is occurring, but not why.  I've looked at
> the API docs for GTK+ and studied the use of gtk_tree_model_get at
> codase.com.  I don't see anything in my code that should cause this
> behavior.  I've also tried to use gtk_tree_model_get_value and the same
> thing occurs.
> 
> Any pointer, hints, outright solutions, or swift kicks in the keister
> would be greatly appreciated.
> 
> TIA,
> 
> Andrew "Weibullguy" Rowland
> 
> ------- CODE FOLLOWS -------
> 
> gboolean
> populate_part_general_tab( GtkTreeModel *model,
>                            GtkTreeIter  *iter )
> {
> 
>     gchar *string = NULL;
>     gfloat *floater;
>     gint *integer;
> 
>     /* Populate the usage information. */
>     gtk_tree_model_get( model, iter, PART_COLUMN_PN, &string, -1 );
>     gtk_entry_set_text( GTK_ENTRY(part_number), string );
>     gtk_tree_model_get( model, iter, PART_COLUMN_REFDES, &string, -1 );
>     gtk_entry_set_text( GTK_ENTRY(ref_des), string );
>     gtk_tree_model_get( model, iter, PART_COLUMN_COMPREFDES, &string, -
> 1 );
>     gtk_entry_set_text( GTK_ENTRY(comp_ref_des), string );
>     gtk_tree_model_get( model, iter, PART_COLUMN_DESC, &string, - 1 );
>     gtk_entry_set_text( GTK_ENTRY(description), string );
>     gtk_tree_model_get( model, iter, PART_COLUMN_QUANT, &integer, - 1 );
>     snprintf(string, 3, "%d", integer);
>     gtk_entry_set_text( GTK_ENTRY(quantity), string );
> 
>     /* Set the part type combo box. */
>     gtk_tree_model_get( model, iter, PART_COLUMN_CLASS, &integer, - 1 );
> 
> AT THIS POINT THE VALUE OF PART_COLUMN_CLASS IS 1, WHICH IS CORRECT
> 
>     gtk_combo_box_set_active( GTK_COMBO_BOX( part_type ), integer);
> 
> AT THIS POINT THE VALUE OF PART_COLUMN_CLASS IS 0, WHICH IS INCORRECT
> 
>     /* Set the part subtype combo box. */
>     gtk_tree_model_get( model, iter, PART_COLUMN_COMP_SUBTYPE, &integer,
> - 1 );
> 
> AT THIS POINT THE VALUE OF PART_COLUMN_CLASS IS 3, WHICH IS INCORRECT
> FOR PART_COLUMN_CLASS.  BUT IS THE CORRECT VALUE OF
> PART_COLUMN_COMP_SUBTYPE.
> 
>     gtk_combo_box_set_active( GTK_COMBO_BOX( part_subclass ), integer );
> 

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

Reply via email to