[Gtk-sharp-list] Re: Sorting a TreeView by clicking the headers

Fredrik Nilsson jymdman@home.se
Wed, 28 Jul 2004 20:08:19 +0200


On ons, 2004-07-28 at 17:51 +0200, Raúl Moratalla wrote: 
> Hi, I had the same problem nad I would like how to solve it :(
> 
> Cheers,
> 
> Raul
> 
> > Hi there,
> > 
> > i've got a question regarding the widget GtkTreeView. I simply want to
> > alphabetically sort a tree (or a list, doesn't matter...) with two
> > columns by clicking at the headers of the TreeView. The only i have
> > found out yet is the attribute TreeView.HeadersClickable. Setting this
> > to true doesn't do anything, apparently. Does anyone here know how to
> > implement this feature? The GUI was created using Glade and i couldn`t
> > find any signals corresponding to this functionality, nor do i know
> > how
> > to adress the headers of the column as they are not an own widget.
> > Many
> > thanks in advance!
> > 
> > Greetings,
> > Chris

Hi,

Try something like this:

// Define Column numbers

enum Column {
	One,
	Two
}

// Setup Treeview

treeview1.HeadersClickable = true;

TreeViewColumn tv = new TreeViewColumn ("Column 1", new CellRendererText
(), "text", (int)Column.One);
treeview1.AppendColumn (tv);
tv.SortColumnId = (int)Column.One; // This do the trick!

tv = new TreeViewColumn ("Column 2", new CellRendererText (), "text",
(int)Column.Two);
treeview1.AppendColumn (tv);
tv.SortColumnId = (int)Column.Two; // This do the trick!


/Fredrik