Re: populate gtk tree view from outside



Oliver,
Thanks for your reply.
The problem basically is to pass on the function argument from one to
other.

So, if I make a more detail, then
In file: main.c I have:
enum
{
  COL_FIRST_NAME = 0,
  COL_LAST_NAME,
  COL_YEAR_BORN,
  NUM_COLS
} ;

static GtkTreeModel *
create_and_fill_model (void)
{
  GtkListStore  *treestore;
  GtkTreeIter    toplevel, child;

  treestore = gtk_list_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_list_store_append(treestore, &toplevel);
  gtk_list_store_set(treestore, &toplevel,
                     COL_FIRST_NAME, alst[i],
                     COL_LAST_NAME, "Average",
                     COL_YEAR_BORN, (guint) 1962,
                     -1);
}

  return GTK_TREE_MODEL(treestore);
}
.....
.....
int main(int argc,
        char *argv[]) {
   view = create_view_and_model();
    gtk_container_add(GTK_CONTAINER(scrolledwindow), view);
    textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
....
....
}


and in another file, update.c I have

void activate_func(GtkWidget *widget, gpointer data) {
   strAuth = gtk_entry_get_text(GTK_ENTRY(e->entryAuth));
    strEditor = gtk_entry_get_text(GTK_ENTRY(e->entryEditor));
....
....
}

Inserting your code snippet directly here obviously gives error like
treestore, COL_FIRST_NAME etc undeclared. So, while your code snippet if
off course useful, can you also help me on passing the arguments
correctly?

On Wed, 2012-09-12 at 17:18 +0200, Olivier Sessink wrote:
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





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