Bugzilla – Bug 313887
ListStore.SetDefaultSortFunc doesn't seem to be working according the documentation.
Last modified: 2007-09-15 21:23:44 UTC
---- Reported by arjen@wiersma.org 2004-02-13 02:05:00 MST ---- Description of Problem: When setting the default sort function on a Gtk.TreeView either the Mono compiler fails or the implementation of the function is off. Failure to set the default sort function results in warnings when running the application. However since this is my first C# and Gtk# application, chances are that I am doing it totally wrong. Steps to reproduce the problem: 1. Create a small gui with Glade 2. Derive a class from Gtk.TreeView 3. In the constructor of the class, try setting the default sort func; ((ListStore)this.Model).SetDefaultSortFunc(new TreeIterCompareFunc(SerieSortFunc), this.Model, new DestroyNotify(ConanTheDestroyer)); Where SerieSortFunc has the following definition: private int SerieSortFunc(TreeModel model,IntPtr a, IntPtr b) and ConanTheDestroyer has this: private void ConanTheDestroyer() Actual Results: When compiling the above, Mono gives an exception in the compiler and the stack trace goes as such: Exception caught by the compiler while compiling: Block that caused the problem begin at: ./SerieTreeView.cs: (20) Block being compiled: [./SerieTreeView.cs: (23),Internal: (1)] System.ArgumentNullException: null key Parameter name: key in Hashtable.Find (object) in Hashtable.GetImpl (object) in Hashtable.get_Item (object) in Invocation.GetParameterData (System.Reflection.MethodBase) in DelegateCreation.Error_NoMatchingMethodForDelegate (Mono.CSharp.MethodGroupExpr, System.Type, System.Reflection.MethodBase, Mono.CSharp.Location) in DelegateCreation.ResolveMethodGroupExpr (Mono.CSharp.EmitContext, Mono.CSharp.MethodGroupExpr) in NewDelegate.DoResolve (Mono.CSharp.EmitContext) in Expression.Resolve (Mono.CSharp.EmitContext, Mono.CSharp.ResolveFlags) in Expression.Resolve (Mono.CSharp.EmitContext) in New.DoResolve (Mono.CSharp.EmitContext) in Expression.Resolve (Mono.CSharp.EmitContext, Mono.CSharp.ResolveFlags) in Expression.Resolve (Mono.CSharp.EmitContext) in Argument.Resolve (Mono.CSharp.EmitContext, Mono.CSharp.Location) in Invocation.DoResolve (Mono.CSharp.EmitContext) in Expression.Resolve (Mono.CSharp.EmitContext, Mono.CSharp.ResolveFlags) in Expression.Resolve (Mono.CSharp.EmitContext) in ExpressionStatement.ResolveStatement (Mono.CSharp.EmitContext) in StatementExpression.Resolve (Mono.CSharp.EmitContext) in Block.Resolve (Mono.CSharp.EmitContext) in Block.Resolve (Mono.CSharp.EmitContext) in EmitContext.EmitTopBlock (Mono.CSharp.Block, Mono.CSharp.InternalParameters, Mono.CSharp.Location) Apperently the delegate can not be found, when it should, since it is stated as such in the docs. Also, the data that needs to be sent in 'IntPtr user_data' is unclear. I figured out this from other Mono applications that use a C library to not have to use the native functionality. Expected Results: I would expect it to compile and happily sort my tree for me of course. How often does this happen? every single time. Additional Information: I am using Gtk# 0.16 ---- Additional Comments From jluke@cfl.rr.com 2004-02-15 16:50:22 MST ---- It would be very helpful if you could attach a small testcase that demonstrates this. That way anyone attempting to fix the bug doesn't have to write their own test. ---- Additional Comments From jluke@cfl.rr.com 2004-04-24 17:05:23 MST ---- Created an attachment (id=165613) test that compiles ---- Additional Comments From jluke@cfl.rr.com 2004-04-24 17:10:16 MST ---- I wrote a test that does nothing but is set up like you describe above with two small exceptions: use IntPtr.Zero for the 2nd argument here ((ListStore) this.Model).SetDefaultSortFunc (new TreeIterCompare Func (SerieSortFunc), IntPtr.Zero, new DestroyNotify (ConanTheDestroyer) ); and this func should have a signature like this int SerieSortFunc (TreeModel model, TreeIter iter1, TreeIter iter2) { } So it seems to work (at least with current cvs), please test the above and close it if it is fixed, or provide more information. Thanks ---- Additional Comments From arjen@wiersma.org 2004-04-29 18:38:15 MST ---- This indeed fixes it... after I added ((ListStore)this.Model).SetSortColumnId(-1, SortType.Ascending); the list also sorts automatically... this was verified agains 0.18 Imported an attachment (id=165613) Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>Gentoo Linux</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other".