[Glade-users] Destroy and rebuild a treeview widget

Mehdi Rabah wrote:
Hi Guillaume,

I'm quite new to gtk/glade but I understand you can't manage the rows of a
treeview from glade2.
So you have to manage treeViewColumn or dataColumn from within your code,
and if you want to remove/add column, you have to use the method of the
treeView class

     Currently with glade-2 or glade-3 there is still no real support
for treeview editing (should be in glade-3 sometime this year...).

If your going to rebuild your treeview I'd suggest you dont bother
building it in glade at all at this point (since you need to setup
all the columns and renderers yourself).

Basicly... after creating and adding the treeview...
gtk_container_remove() should be enough to remove the treeview
from its container and destroy it... at which point you should
create your new treeview and add it to the hierarchy.


Once again, thanks for your rapid answer :) In fact, like medhi, I wanted to use clist, but it's
deprecated so...  I cant really understand treeview/liststore, even with the gtk tutorials, I
think I'm in the right way, but I know I lack 2 or 3 things to make it work... Can you have a look
on this?


  GtkCellRenderer       *rend;
  GtkTreeViewColumn     *col;
  GtkWidget             *listview;
  GtkListStore          *liststore;
  gchar                 *sql, *label;
  MYSQL_RES             *res_str;
  MYSQL_FIELD           *field;
  MYSQL_ROW              db_row;
  gint                   i, cols;
  gchar     *row[20] = {"", "", "", "", "",
                        "", "", "", "", "",
                        "", "", ""};

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");
      return 0L;
  res_str = mysql_store_result (conn);

/**********************Cr?ation de la liste****************/
   cols = mysql_num_fields(res_str);

   liststore= gtk_list_store_new(gint cols);

   while ((db_row = mysql_fetch_row (res_str)) != 0L)
        for (i = 0; i < cols; i++)
              row[i] = db_row[i];
        gtk_list_store_append(liststore, row);


/* Creation de la vue */

listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore));

for (i = 0; i < cols; i++)
       mysql_field_seek(res_str, i);
       field = mysql_fetch_field(res_str);
       label = gtk_label_new (field->name);
       rend = gtk_cell_renderer_text_new();
       col = gtk_tree_view_column_new_with_attributes(label,
       rend,"text", TEXT_COLUMN, NULL);
       gtk_tree_view_append_column(GTK_TREE_VIEW(listview), col);

    gtk_widget_show (listview)


This may display the contents of mysql_fetch_row on each row till it returns null, but I don't
know how to add data and I can't find the answer (i'm sure it's on the tutorial but...) After, a
click on  a button will remove the data and rebuild it (I hope the dynamic column creation is
right...) Content will never excess 13 columns.

Thanks to this great useful list


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