Treeview doesnt refresh upon reopenning window
- From: Jason Brisbane <darkeen westnet com au>
- To: Glade-Users <glade-users lists ximian com>, Glade App-Devel-List <gtk-app-devel-list gnome org>
- Subject: Treeview doesnt refresh upon reopenning window
- Date: Mon, 23 Apr 2007 22:14:50 +0800
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);
}
}
}
}
--
Regards,
Jason Brisbane
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]