[Gtk-sharp-list] Apparently trivial: problem casting from object to
int
Callum J. Bell
cjb at seirad.com
Tue Jan 17 15:19:39 EST 2006
I'm posting to this group because the origin of the problem is sorting
columns in a ListStore that is a model for a TreeView. I want to sort
a column of integers so I started writing a sortfunction:
public int int_compare(TreeModel m, TreeIter a, TreeIter b)
{
GLib.Value x = new GLib.Value();
GLib.Value y = new GLib.Value();
m.GetValue(a,3,ref x);
m.GetValue(b,3,ref y);
// At runtime the next two lines throw: Unhandled Exception:
//System.InvalidCastException: Cannot cast from source type to
//destination type.
int i = (int)(x.Val);
int j = (int)(y.Val);
// But x.Val does contain an integer that gets unboxed correctly
// here:
System.Console.WriteLine(">> " + x.Val + " <<");
// Never got this far...
//return i.CompareTo(j);
// This is for debugging
return 1;
}
It looks to me as if the cast should work. Any ideas? Also, if there
are sortfunctions out there for various types I'd appreciate a pointer
to them.
Thanks
Callum
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cjb.vcf
Type: text/x-vcard
Size: 223 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20060117/6a50a9ec/cjb.vcf
More information about the Gtk-sharp-list
mailing list