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

Charles Mason cemasoniv at gmail.com
Wed Apr 23 15:31:16 CEST 2008


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)?

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


More information about the Ironpython-users mailing list