Re: Update a GtkTreeView



On Sun, Jan 26, 2003 at 01:24:55PM +0100, Emmanuel Di Pretoro wrote:

My list is sorted by name of authors, so, must I clear my
GtkListStore, and recreate it ? 

OK, hereby the found solution :

When I've updated my database, I call 'gtk_tree_view_set_model' with as
args my GtkTreeView and a function creating a new model. 

This defeats the utility of the model-view pattern, though.

I think you can just set the sort column to the author column.  I'm not sure
what happens when you append something out of order to the ListStore,
though.  Anybody?

gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(yourliststore), 
                                     AUTHOR_COLUMN, GTK_SORT_ASCENDING);

Where AUTHOR_COLUMN is whatever column author is in the ListStore.

Also, there is TreeModelSort. I have not tried it myself. I think the intent
is that the TreeModelSort tracks changes in the child TreeModel while
allowing you to keep the original ordering of the ListStore unchanged.

model_sort = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(yourliststore));
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model_sort), 
                                     AUTHOR_COLUMN, GTK_SORT_ASCENDING);
gtk_tree_view_set_model(treeview, model_sort);

Also, if possible, try using the ListStore as your data structure for the
author list rather than keeping a redundant data structure around.

Dave Cook



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