[Glade-users] Re: Destroy and rebuild a treeview widget
- From: guillaume at ruch.infini.fr (Ruch Guillaume)
- Subject: [Glade-users] Re: Destroy and rebuild a treeview widget
- Date: Mon Jun 5 18:57:42 2006
Hi,
Can somebody tell me what's the function to display a new widget in a
container? I finally managed to build my dynamic tree (thanks
Tristan ;) ) but It still displays nothing... I tried to use
gtk_container remove/add but it didnt change anything... Got an idea?
I think it'd work if i destroy.rebuild the whole window but maybe
there's another way...
Code ( just the bugged function) :
void
on_btn1menuC_clicked (GtkButton *button,
gpointer user_data)
{
gchar *nom_table;
connexion(conn);
nom_table = "clients";
g_print("table name : %s...\n", nom_table);
GtkTreeIter iter;
GtkCellRenderer *rend;
GtkTreeViewColumn *col;
GtkWidget *treeview;
GtkListStore *liststore;
gchar *sql, *label;
MYSQL_RES *res_str;
MYSQL_FIELD *field;
MYSQL_ROW db_row;
gint i, cols, rows;
GType *types;
GList *list,*l;
treeview= glade_xml_get_widget (xml, "treeview1");
scwindow = glade_xml_get_widget (xml, "scrolledwindow8");
liststore =
(GtkListStore*)gtk_tree_view_get_model( GTK_TREE_VIEW(treeview) );
gtk_tree_view_set_model( GTK_TREE_VIEW(treeview), NULL );
l = list = gtk_tree_view_get_columns( GTK_TREE_VIEW(treeview) );
while ( l != NULL )
{
g_print("Colonne supprim?e\n");
gtk_tree_view_remove_column(
GTK_TREE_VIEW( treeview ),
GTK_TREE_VIEW_COLUMN( l->data )
);
l = g_list_next( l );
}
g_list_free( list );
sql = g_strconcat("select * from ", nom_table, 0L);
g_print("sql is: %s\n", sql);
if (mysql_query (conn, sql) != 0)
{
g_print("Echec de la requete...\n");
}
res_str = mysql_store_result (conn);
cols = mysql_num_fields(res_str);
types = (GType*)g_malloc0( cols * sizeof( GType* ) );
types[0] = G_TYPE_INT;
for (i = 1; i < cols; i++)
{
types[i] = G_TYPE_STRING;
}
liststore=gtk_list_store_newv (cols, types);
g_free (types);
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview),
GTK_TREE_MODEL(liststore));
field = mysql_fetch_field(res_str);
for (i = 0; i < cols ; i++)
{
g_print("%i\n",i);
rend = gtk_cell_renderer_text_new();
col = gtk_tree_view_column_new_with_attributes(g_strdup
(field[i].name), rend, "text", i, NULL);
g_print("%s...OK\n" , (field[i].name));
}
while ((db_row = mysql_fetch_row (res_str)) != 0L)
{
for (i = 0; i < cols ; i++)
{
gtk_list_store_append(liststore, &iter);
gtk_list_store_set(liststore, &iter, i, db_row[i], -1 );
}
}
mysql_free_result(res_str);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]