Fwd: Reading row from a ComboBox

Thanks Damien, it works fine!

----- Forwarded message from omar crea jusan it -----
    Date: Fri, 28 Sep 2007 16:05:46 +0200
    From: omar crea jusan it
Reply-To: omar crea jusan it
 Subject: Reading row from a ComboBox
      To: GTK+ mailing list <gtk-app-devel-list gnome org>

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.


enum {

/* main function */
model = create_model();
c.Combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(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>",

     while (tmp != NULL) {
         gtk_tree_store_append(store, &iter, NULL);
         gtk_tree_store_set(store, &iter,
                 STRING_COL, tmp->content,
         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,

     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_combo_box_set_active_iter(combo, &iter);

This message was sent using IMP, the Internet Messaging Program.

----- End forwarded message -----

This message was sent using IMP, the Internet Messaging Program.

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