[IronPython] System.Windows.Forms.PropertyGrid and Python objects

Pigneri, Rocco rpigneri at LavaStorm.com
Wed Apr 23 17:00:40 CEST 2008

Dear Charles,
I ran into the same problem you are experiencing a few months ago while
using Python 1.1.  The problem is that the WinForms reflection is
looking for static properties.  IronPython 1.1 objects, being dynamic,
lack the proper metadata to guide the WinForms classes to do the right
Try 1.1.1.  That will allow WinForms to find a *whole* lot of things
(including all your public methods).  My guess is that it may be easier
for you to turn off these extra elements rather than to create a
separate C# assembly to hold static interfaces.
It would be great to clean up these staticized properties in 1.1.2 to
include only properties defined with the "property" function.  That
would really help anyone using static data binding in WinForms (or any
other part of the BCL for that matter).
Hope that helps,


From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Charles Mason
Sent: Wednesday, April 23, 2008 9:31 AM
To: users at lists.ironpython.com
Subject: [IronPython] System.Windows.Forms.PropertyGrid and Python

So I've been through hell last night tearing my hear out trying to
figure out how to work PropertyGrid properly with a Python class object.

Things I've tried:

1) In Python, PropertyGrid.SelectedObject = pythonobj 
2) In Python, Deriving PropertyGrid and overriding CreatePropertyTab
3) In C#, deriving a new class from PropertyGrid and implementing

public void SetPythonObject(Object obj)
  this.SelectedObject = obj;

4) In C#, Overriding CreatePropertyTab() (I get a warning about hiding a
baseclass implementation -- sounds like this isn't overrideable)
5) In C#, creating a wrapper class:

class CustomHolder
  private Object heldObj = null;
  public Object held {
    get { return heldObj; }
    set { heldObj = value; }
  CustomHolder(Object obj) 
    this.held = obj;

and in the derived PropertyGrid class:

public void SetPythonObject(Object obj)
  this.SelectedObject = new CustomHolder(obj);


Only #5 so far has done anything worthwhile: In the property grid as a
single field I get what looks like str(obj) output:
<module.CLASSNAME instance at 0x................>

I've also considered using the TypeDescriptor() class/methods to create
each property grid entry myself, but I don't see anything at all about
where PropertyGrid gets its property fields from -- see #4.

Is there any way to do this conveniently (I'd prefer not to write a C#
custom dll, but am amiable to the requirement of doing so)?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080423/8d26371d/attachment.html>

More information about the Ironpython-users mailing list