----- Original Message ---- From: Jason Brisbane <[EMAIL PROTECTED]> To: Glade-Users <[EMAIL PROTECTED]>; Glade App-Devel-List <gtk-app-devel-list@gnome.org> Sent: Monday, April 23, 2007 10:14:50 AM Subject: Treeview doesnt refresh upon reopenning window
Hello All, I am looking for a fix for a Treeview issue that I am having. I have created a Treeview that gets its data from a database and populates the list with the results of the database. This works well as even if the database table was empty (rows=0) then it still displays the headers (better than I thought). In my example, I have a treeview on one half of the screen and the database fields showing the data on the right (table). This shows the data just wonderfully. If I add a record, or conversely if I select a record and delete it, the treeview doesnt get updated. I am calling the _show function after each time, but I dont believe that the gtk_destroy_treeview is actually doing its job. Surely it would kill the treeview, model, store, and everything with it when you kill it? Here is the "_show" code. Of course this works fine on starting the window the first time but doesnt refresh. I get the following message when the window tries to update: (battlemaster:11819): Gtk-CRITICAL **: gtk_scrolled_window_add: assertion `bin->child == NULL' failed PS: Do I need to g_free/g_object_unref the list_store or other objects before returning? Thanks in advance. ---- void on_monstertype_show (GtkWidget *widget, gpointer user_data) { gchar *sql; MYSQL *conx; MYSQL_RES *result_set; MYSQL_ROW db_row; MYSQL_FIELD *field; GtkListStore *list_store; GtkTreeModel *model; GtkTreeIter iter; GtkWidget *view; GtkCellRenderer *renderer; GtkTreeSelection *selection; gtk_widget_destroy(lookup_widget(widget, "treeview4")); /* First, connect to the database. */ conx = mysql_init(0L); if (conx != 0L) { conx = mysql_real_connect(conx, LOCALHOST, USER, PASS, DBASE,0,0L,0); if (conx != 0L) { sql = g_strconcat("select monsterid, creaturetype from monstertype ; ", 0L); if (mysql_query (conx, sql) == 0) { result_set = mysql_store_result (conx); // CREATE THE TREE_VIEW and hook the row selection event into it! view = gtk_tree_view_new(); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_select_function(selection, mt_selection_func, NULL, NULL); // CREATE COLUMN HEADERS // -- Column 1 -- renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, "ID", renderer, "text", COLUMN_ONE, NULL); // -- Column 2 -- renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, "Type", renderer, "text", COLUMN_TWO, NULL); // Now Fill with the Data list_store = gtk_list_store_new (2,G_TYPE_STRING, G_TYPE_STRING); // ADD ONE ROW FOR EACH MYSQL ROW RETRIEVED while ((db_row = mysql_fetch_row (result_set)) != 0L) { // Display the Columns in the gtkListstore gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, COLUMN_ID, db_row[0], COLUMN_LOCATION, db_row[1], -1 ); } model = GTK_TREE_MODEL(list_store); gtk_tree_view_set_model (GTK_TREE_VIEW(view), model); g_object_unref (model); gtk_container_add (GTK_CONTAINER(lookup_widget(widget, "scrolledwindow4")), view); gtk_widget_show_all(widget); mysql_close(conx); } } } } Jason, You need to reconsider how your using the TreeView. Your are creating and loading everything every time; and not checking to see that "lookup_widget()" in calls like gtk_widget_destroy(lookup_widget(widget, "treeview4"));, actually returned a vaild value -- this is the cause of your error messages. Let me suggest an alternate sequence based on your scenario. Start of Program: 1. Create ListStore 2. Create TreeView using liststore 3. Open DataBase, insert/append records to list store. 4. some data change occurs (you may have to periodically count db.rows or something) 5. read from Database 6. Check to see if record exist in liststore (if yes, skip; else append) 7. goto step 4; unless exit signal 8. If exit signal, be nice and destroy TreeView TreeView's can last forever and will automatically update when their datastore is updated. The trick is to keep the liststore updated without purging it and reloading everything. There are several programming methods that would allow you to update the liststore when you update the database - these are of course defeated when some other program updates the database. I have not looked to see if SQL has a way of informing a program that certain data tables have been modified - i just don't know. It would be worth considering or searching for! James, -- Regards, Jason Brisbane _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list