[Gtk-sharp-list] Sorting a TreeView by clicking the headers
Peter Williams
peter@newton.cx
Thu, 01 Jul 2004 16:28:44 -0400
Hi,
There is indeed a Clicked event that a TreeViewColumn will emit. The
problem I had is that it didn't seem to be possible to unsort the
columns once they got sorted. Here's some code I used (warning: old and
hasn't been tested in a while):
public abstract class WonderColumn : TreeViewColumn {
public enum SortState { None, Up, Down };
protected SortState sort;
public WonderColumn () : base () {
// ...
Clickable = true;
sort = SortState.None;
SortColumnId = TextColumn;
Clicked += new EventHandler (OnClicked);
}
// ....
protected void OnClicked (object sender, EventArgs args) {
switch (sort) {
case SortState.None:
sort = SortState.Down;
break;
case SortState.Down:
sort = SortState.Up;
break;
case SortState.Up:
// would like to go back to SortState.None
sort = SortState.Down;
break;
}
switch (sort) {
case SortState.None:
SortIndicator = false;
break;
case SortState.Down:
SortIndicator = true;
SortOrder = SortType.Ascending;
break;
case SortState.Up:
SortIndicator = true;
SortOrder = SortType.Descending;
break;
}
}
}
Peter
On Wed, 2004-06-30 at 17:07, Christian Ziegner wrote:
> 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
>
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
--
Peter Williams peter@newton.cx
"[Ninjas] are cool; and by cool, I mean totally sweet."
-- REAL Ultimate Power