[Gtk-sharp-list] cellrendererprogress confusion
m.j.hutchinson at gmail.com
Wed Feb 18 03:01:22 EST 2009
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)
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, "clarence clarence" <catchfire at gmail.com> wrote:
I guess i should be a bit more specific than my initial hand wavy post....
So at the moment i have a...
Dictionary<int, thing> thingDictionary = new Dictionary<int, thing>();
to that i have added a new object of type 'thing" (the 'thing' object
generates a number from 1 to 100 every second)....
i create my ListStore etc....
Gtk.ListStore store = new Gtk.ListStore(typeof(thing));
treeview1.AppendColumn("gear", new Gtk.CellRendererProgress(),new
treeview1.Model = store;
The error I am getting is a "Cannot cast from source type to destination
type" at the line indicated.....
public void renderit(Gtk.TreeViewColumn col, Gtk.CellRenderer cell,
Gtk.TreeModel model, Gtk.TreeIter iter)
Error Here -> thing tt = (thing) model.GetValue(iter,0);
(cell as Gtk.CellRendererProgress).Value = tt.time;
Hope that is not too confusing ;)
On Wed, Feb 18, 2009 at 1:22 PM, clarence clarence <catchfire at gmail.com>
wrote: > > hello. > > i a...
Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gtk-sharp-list