[Gtk-sharp-list] Problem with sorting TreeView.

David S buttink at gmail.com
Thu Jul 29 14:05:25 EDT 2010


All you really need to do is call SetSortFunc and then SetSortColumnId like
so. I will say my sort is a bit complicated so if you need more help
go here<http://www.go-mono.com/docs/index.aspx?link=M:Gtk.ListStore.SetSortFunc(System.Int32,Gtk.TreeIterCompareFunc)>
.

// set sort function for 2nd column
diffStore.SetSortFunc( 2, (TreeModel model, TreeIter a, TreeIter b) => {
RegexMove commandA = model.GetValue( a, 0 ) as RegexMove; RegexMove commandB
= model.GetValue( b, 0 ) as RegexMove; string seasonStringA; int seasonA =
-1; string seasonStringB; int seasonB = -1; string episodeStringA; int
episodeA = -1; string episodeStringB; int episodeB = -1;
commandA.Match.NamedGroups.TryGetValue( "season", out seasonStringA );
commandB.Match.NamedGroups.TryGetValue( "season", out seasonStringB );
commandA.Match.NamedGroups.TryGetValue( "episode", out episodeStringA );
commandB.Match.NamedGroups.TryGetValue( "episode", out episodeStringB );
int.TryParse(seasonStringA, out seasonA); int.TryParse(seasonStringB, out
seasonB); int.TryParse(episodeStringA, out episodeA);
int.TryParse(episodeStringB, out episodeB); if ( seasonA.CompareTo( seasonB
) == 0 ) return episodeA.CompareTo( episodeB ); else return
seasonA.CompareTo( seasonB ); });
// set the sort column to the 2nd diffStore.SetSortColumnId( 2,
SortType.Ascending );

On Thu, Jul 29, 2010 at 7:05 AM, Tensai Cirno <tensai at cirno.in> wrote:

> I've got treeview with complex liststore.
>
> Treeview has only 1 column with 2 cellrenderers (pixbuf and text) and
> liststore 3 fields (pixbuf, text and internal bool).
>
> I've written SortFunc and set liststore.DefaultSortFunc = SortFunc. What
> i should do to perform sorting itself? Not just Ascending/Descending
> sort of 1 column, but complex sort with SortFunc.
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20100729/5d2dc37c/attachment-0001.html 


More information about the Gtk-sharp-list mailing list