populate gtk tree view from outside
Dear friends, I have defined a treeview model as follows: enum { COL_FIRST_NAME = 0, COL_LAST_NAME, COL_YEAR_BORN, NUM_COLS } ; static GtkTreeModel * create_and_fill_model (void) { GtkTreeStore *treestore; GtkTreeItertoplevel, child; treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT); int i; FILE *fauth; char alst[10][500], buffer[500]; fauth=fopen(fauth.dat,r); if(!fauth){ printf(fauth failed\n); } while(fgets(buffer,500,fauth)){ strcpy(alst[i],buffer); i++; } fclose(fauth); for (i = 0; i 10; i++){ gtk_tree_store_append(treestore, toplevel, NULL); gtk_tree_store_set(treestore, toplevel, COL_FIRST_NAME, alst[i], COL_LAST_NAME, Average, COL_YEAR_BORN, (guint) 1962, -1); } return GTK_TREE_MODEL(treestore); } static GtkWidget * create_view_and_model (void) { GtkTreeViewColumn *col; GtkCellRenderer *renderer; GtkWidget *view; GtkTreeModel*model; view = gtk_tree_view_new(); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, First Name); gtk_tree_view_append_column(GTK_TREE_VIEW(view), col); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, text, COL_FIRST_NAME); gtk_tree_view_column_pack_start(col, renderer, TRUE); model = create_and_fill_model(); gtk_tree_view_set_model(GTK_TREE_VIEW(view), model); g_object_unref(model); gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), GTK_SELECTION_NONE); return view; } //For brevity, I have cut out the 2nd and 3rd column In a different function, I have strAuth = gtk_entry_get_text(GTK_ENTRY(e-entryAuth)); strEditor = gtk_entry_get_text(GTK_ENTRY(e-entryEditor)); Is it possible to add these strAuth, strEditor in those treeview's 1st and 2nd column? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: populate gtk tree view from outside
On 09/12/2012 12:21 PM, Rudra Banerjee wrote: [..] strAuth = gtk_entry_get_text(GTK_ENTRY(e-entryAuth)); strEditor = gtk_entry_get_text(GTK_ENTRY(e-entryEditor)); Is it possible to add these strAuth, strEditor in those treeview's 1st and 2nd column? just acquire an iterator at the right position, and set the columns, for example gtk_tree_model_get_iter_first(GTK_TREE_MODEL(treestore), iter); gtk_tree_store_set(treestore, iter, COL_FIRST_NAME, strAuth, COL_LAST_NAME, strEditor, -1); regards, Olivier ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: populate gtk tree view from outside
On 09/12/2012 06:30 PM, Rudra Banerjee wrote: Oliver, Thanks for your reply. The problem basically is to pass on the function argument from one to other. you need to create a header file (main.h) that has the enum, and extern GtkListStore *treestore; in main.c define GtkListStore *treestore; somewhere in the top of fthe file, *not* inside a function. then include this both in main.c and in otherfile.c like #include main.h Olivier ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: populate gtk tree view from outside
Oliver, Thanks a lot. Its working properly. Only change that I have made is using gtk_tree_store_append in place of gtk_tree_model_get_iter_first. Thanks a lot again. Regards, On Wed, 2012-09-12 at 21:31 +0200, Olivier Sessink wrote: On 09/12/2012 06:30 PM, Rudra Banerjee wrote: Oliver, Thanks for your reply. The problem basically is to pass on the function argument from one to other. you need to create a header file (main.h) that has the enum, and extern GtkListStore *treestore; in main.c define GtkListStore *treestore; somewhere in the top of fthe file, *not* inside a function. then include this both in main.c and in otherfile.c like #include main.h Olivier ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list