[Gtk-sharp-list] Custom CellRenderer

Nicholas Frechette zeno490 at gmail.com
Tue Feb 1 10:44:24 EST 2011

To further clarify what I am attempting to do and why it isn't working:
I am attempting to have 1 column in a tree view use multiple cellrenderers
but mostly only show one at a time per row (one of: toggle, text, combo,
To achieve this, I thought of two ways to accomplish this:
1- Implement a custom cellrenderer and forward every call to the one
sub-renderer desired
2- Have all cellrenderers packed into the column and only have 1 visible at
a time

In attempting 1, I discovered that, unlike the C++ bindings, the C# bindings
do not have the same behavior.
For example, on a CellRenderer, the Activate function in gtk# is not marked
virtual. So, while it is exposed and you can call it fine, the function
itself will never be called by the library when a cell would activate. It
appears that the C++ library only calls a certain number of functions into
C# and Activate isn't one of them. This is also the case for properties.
While exposed in C# as properties and allows setting them and retrieving
them from the C# side, under the hood, the C++ library never calls those
properties and as such nothing fancy can be done with them (and thus they
cannot be overridden). This somewhat breaks the assumptions one makes
looking at the documentation/API.

Am I understanding this correctly? Is 2 the only option to accomplish this?


On Sun, Jan 30, 2011 at 12:17 PM, Nicholas Frechette <zeno490 at gmail.com>wrote:

> Hi,
> I am attempting something similar to the following:
> http://kapo-cpp.blogspot.com/2008/05/different-cellrenderers-on-same-column.html
> To achieve the same behavior with gtk#, I created a proxy interface as he
> does to expose the protected render method required. I then created a
> version of each cell renderer that inherits the interface and the renderer
> desired (ie: CellRendererComboProxy) that forwards all the calls to the base
> class.
> I then have a simple converter cell renderer that takes a key as a property
> and forwards all the method calls to the proper cell renderer afterwards.
> This appears to work fine for rendering static data. I can see the spin
> button value, the checkbox marked, etc.
> However, I cannot edit any of the values. The StartEditing function never
> appears to be called, nor the Activate function.
> I do set my cellrenderers to be activatable and editable but no luck. I
> even attempted to override all the properties in cellrenderer in my
> converter to forward the property calls to the correct cellrenderer without
> further luck.
> I did run into the following problem though:
> System.Reflection.TargetInvocationException: Exception has been thrown by
> the target of an invocation. ---> System.InvalidOperationException:
> GLib.PropertyAttribute cannot be applied to property Mode of type
> CellRendererConverter because the return type of the property is not
> supported
>   at GLib.Object.AddProperties (GType gtype, System.Type t) [0x00000] in
> <filename unknown>:0
>   at GLib.Object.RegisterGType (System.Type t) [0x00000] in <filename
> unknown>:0
> With the following code in my custom cell renderer:
> [GLib.Property("mode")]
> public new CellRendererMode Mode { get; set; } // Impl not shown, problem
> still occurs without 'new' here
> Strangely enough, the same code in the gtk# cellrenderer appears to work
> fine.
> Is there a better way to achieve a treeview in which I can display 2
> columns and edit values of various types in the second? (Much like a
> property grid)
> Regards,
> Nicholas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20110201/3db4bcbe/attachment.html 

More information about the Gtk-sharp-list mailing list