Date: Wed, 15 Jun 2005 00:11:10 +0200 (CEST) Message-Id: <20050615.001110.92572391.oandrieu at nerim.net> To: dmentre at linux-france.org Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: How to make column headers in a tree view clickable for sorting? From: Olivier Andrieu In-Reply-To: <87vf4gy6rn.fsf at linux-france.org> References: <87vf4gy6rn.fsf at linux-france.org> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Wed_Jun_15_00_11_10_2005_808)--" Content-Transfer-Encoding: 7bit ----Next_Part(Wed_Jun_15_00_11_10_2005_808)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit > David MENTRE [Tue, 14 Jun 2005]: > > Hello, Hi, > In my program, I'm following sortable.ml example as found in > Lablgtk2 Tree View Tutorial to make sortable columns. However, in > the example, one can't change sort order by clicking on column > headers. How can I do that? You have to assign a sort_column_id to the GtkTreeViewColumn so that GTK+ can "link" the sort function attached to the GtkTreeModel (via its GtkTreeSortable interface) to the GtkTreeViewColumn header. -- Olivier ----Next_Part(Wed_Jun_15_00_11_10_2005_808)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sortable.patch" --- sortable.ml.orig 2005-06-15 00:05:35.000000000 +0200 +++ sortable.ml 2005-06-15 00:04:57.000000000 +0200 @@ -21,11 +21,6 @@ liststore -let compare a b = - if a < b then -1 - else if a > b then 1 - else 0 - let sort_by_name (model:#GTree.model) row1 row2 = let name1 = model#get ~row:row1 ~column:col_name in let name2 = model#get ~row:row2 ~column:col_name in @@ -52,6 +47,7 @@ let col = GTree.view_column ~title:"Name" ~renderer:(renderer_text, [("text", col_name)]) () in (* pack tree view column into tree view *) + col#set_sort_column_id col_name.index ; view#append_column col; (* Column #2 *) @@ -59,6 +55,7 @@ (* create tree view column and pack cell renderer into tree view column *) let col = GTree.view_column ~title:"Year Born" ~renderer:(renderer_text, [("text", col_year_born)]) () in + col#set_sort_column_id col_year_born.index ; (* pack tree view column into tree view *) view#append_column col; ----Next_Part(Wed_Jun_15_00_11_10_2005_808)----