views:

69

answers:

1

Problem: when object is having:

class A
{
    public ISomeinterface PropertyName { get; set; }
}

and then an instance of that class is assigned to propertyGrid.SelectedObject = new A(); then when trying to edit the value of PropertyName, an exception about fail to make instance of ISomeinterface is shown (make sense of course) the question is how to workaround this without break my class's and interfaces.?

+1  A: 

Right, PropertyGrid has no hope of guessing how to assign the value. So, hide it:

class A
{
    [Browsable(false)]
    public ISomeinterface PropertyName { get; set; }
}

If property assignment is a requirement then you'll need to implement a UITypeEditor for the property.

Hans Passant
But I don't understands way if I have a say ISomeInterface[] and than I have A,B that implements this interface, way can't there be an editor which allows me to Add A or B? isn't there is some trick to overcome this? Because I have built an Editor and it works but this is kind of redundant because it should be rendered automatically, that's the whole point no?