mail-archives/gtk-sharp-list/2009-February/009432.html

132 строки
5.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Gtk-sharp-list] cellrendererprogress confusion
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20cellrendererprogress%20confusion&In-Reply-To=aec34c770902172340k44207711ydb330f1aea61ac70%40mail.gmail.com">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="009431.html">
<LINK REL="Next" HREF="009433.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Gtk-sharp-list] cellrendererprogress confusion</H1>
<B>Michael Hutchinson</B>
<A HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20cellrendererprogress%20confusion&In-Reply-To=aec34c770902172340k44207711ydb330f1aea61ac70%40mail.gmail.com"
TITLE="[Gtk-sharp-list] cellrendererprogress confusion">m.j.hutchinson at gmail.com
</A><BR>
<I>Wed Feb 18 03:01:22 EST 2009</I>
<P><UL>
<LI>Previous message: <A HREF="009431.html">[Gtk-sharp-list] cellrendererprogress confusion
</A></li>
<LI>Next message: <A HREF="009433.html">[Gtk-sharp-list] cellrendererprogress confusion
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#9432">[ date ]</a>
<a href="thread.html#9432">[ thread ]</a>
<a href="subject.html#9432">[ subject ]</a>
<a href="author.html#9432">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>The AddValues method on the ListStore adds any number of objects to the
columns of a single row, and unfortunately it's not strongly typed
(primitive types are mapped to equivalent unmanaged types, which AFAIK is
why you set up the type for the store and you can map these columns to cell
renderer properties directly). This means your store has one row, containing
a dictionary, which obviously can't be cast to 'thing'.
You probably want something like
foreach (thing t in thingDictionary.Values)
store.AppendValues (t);
Btw, where you're using an 'as' cast, you should use a () cast. The 'as'
casts are useful when you expect them to fail sometimes in ordinary
circumstances, because you can check for null. If you don't handle null
you're just going to get a NullReferenceException when you try to use the
casted value, whereas if a () cast fails, you get an InvalidCastException,
which makes it more apparent where the problem is.
On Feb 18, 2009 12:27 AM, &quot;clarence clarence&quot; &lt;<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">catchfire at gmail.com</A>&gt; wrote:
I guess i should be a bit more specific than my initial hand wavy post....
So at the moment i have a...
Dictionary&lt;int, thing&gt; thingDictionary = new Dictionary&lt;int, thing&gt;();
to that i have added a new object of type 'thing&quot; (the 'thing' object
generates a number from 1 to 100 every second)....
thingDictionary.Add(new thing());
i create my ListStore etc....
Gtk.ListStore store = new Gtk.ListStore(typeof(thing));
treeview1.AppendColumn(&quot;gear&quot;, new Gtk.CellRendererProgress(),new
TreeCellDataFunc(renderit));
store.AppendValues(thingDictionary);
treeview1.Model = store;
The error I am getting is a &quot;Cannot cast from source type to destination
type&quot; at the line indicated.....
public void renderit(Gtk.TreeViewColumn col, Gtk.CellRenderer cell,
Gtk.TreeModel model, Gtk.TreeIter iter)
{
Error Here -&gt; thing tt = (thing) model.GetValue(iter,0);
(cell as Gtk.CellRendererProgress).Value = tt.time;
}
Hope that is not too confusing ;)
Cheers
Gary A
On Wed, Feb 18, 2009 at 1:22 PM, clarence clarence &lt;<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">catchfire at gmail.com</A>&gt;
wrote: &gt; &gt; hello. &gt; &gt; i a...
--
__________
wow
_______________________________________________
Gtk-sharp-list maillist - <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">Gtk-sharp-list at lists.ximian.com</A>
<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">http://lists.ximian.com/mailman/listinfo/gtk-sharp-list</A>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <A HREF="http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20090218/823a9b71/attachment.html">http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20090218/823a9b71/attachment.html</A>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="009431.html">[Gtk-sharp-list] cellrendererprogress confusion
</A></li>
<LI>Next message: <A HREF="009433.html">[Gtk-sharp-list] cellrendererprogress confusion
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#9432">[ date ]</a>
<a href="thread.html#9432">[ thread ]</a>
<a href="subject.html#9432">[ subject ]</a>
<a href="author.html#9432">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">More information about the Gtk-sharp-list
mailing list</a><br>
</body></html>