Hi everybody. I have a problem on reading the actually displayed content of a combobox. I created a combobox that contains some strings and I want to recover the actually displayed string when i press the "Find" button (that is a button in the same window of the combobox). The problem is that the 'gtk_tree_model_get_iter' function always returns FALSE ('getted' is FALSE when running app). I tried also with the following code:
gint row; row = gtk_combo_box_get_active (combo); path = gtk_tree_path_new_from_indices (row, -1); but without success. :-( Here are my questions: 1) how can I get a valid iter from the tree model? Is there something wrong with the path? 2) when I obtain the current iter, how can I get the selected entry of the combobox? I need to save it to a string for subsequent processing. Thanks in advance. Omar enum { STRING_COL, NUM_COL }; /* main function */ ... model = create_model(); c.Combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model)); add_renderer(GTK_COMBO_BOX(c.Combo)); g_object_unref(model); ... /* create_model function */ static GtkTreeModel * create_model ( void ) { GtkTreeIter iter; GtkTreeStore *store = NULL; GtkTreeSelection *select = NULL; GtkWidget *treeview = NULL; ll *tmp = top->ref->first; store = gtk_tree_store_new(NUM_COL, G_TYPE_STRING); gtk_tree_store_append(store, &iter, NULL); gtk_tree_store_set(store, &iter, STRING_COL, "<Nothing>", -1); while (tmp != NULL) { gtk_tree_store_append(store, &iter, NULL); gtk_tree_store_set(store, &iter, STRING_COL, tmp->content, -1); tmp = tmp->next; } treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); select = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); return GTK_TREE_MODEL(store); } /* add_renderer function */ static void add_renderer ( GtkComboBox *combo ) { GtkCellRenderer *render = NULL; GtkTreePath *path = NULL; GtkTreeModel *mod = NULL; GtkTreeIter iter; gboolean getted; gint row; render = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), render, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), render, "text", STRING_COL, NULL); path = gtk_tree_path_new_from_indices(0, 8, -1); mod = gtk_combo_box_get_model(combo); getted = gtk_tree_model_get_iter(mod, &iter, path); printf("getted is %s\n", (getted) ? "TRUE" : "FALSE"); gtk_tree_path_free(path); gtk_combo_box_set_active_iter(combo, &iter); } ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list