开发者

c# PropertyGrid and Interface property

开发者 https://www.devze.com 2023-01-15 15:16 出处:网络
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();

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 wo开发者_C百科rkaround this without break my class's and interfaces.?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消