Editing a property of an object inside an object in PropertyGrid

被刻印的时光 ゝ 提交于 2019-12-11 12:17:31

问题


I'm trying to make an object, configureable/editable with a propertygrid. This is all going well, except for objects inside objects.

I've got an object/class named "ContactInformation". And inside that object I've got an object named "Correspondence".

This is how that part looks:

[Browsable(false)]
public Correspondence Correspondence
{
    get;
    set;
}
public int CorrespondenceStatus 
{
    get { return this.Correspondence.Status; }
    set { this.Correspondence.Status = CorrespondenceStatus; }
}
public string CorrespondenceComment
{
    get { return this.Correspondence.Comment; }
    set { this.Correspondence.Comment = CorrespondenceComment; }
}
public DateTime CorrespondenceDate
{
    get { return this.Correspondence.LastSend; }
    set { this.Correspondence.LastSend = CorrespondenceDate; }
}

That way I can show the properties/variables of the object inside the object, in the propertygrid.

Anyway, when I edit the values now, and press enter, or click somewhere else, instead of keeping it the value I just typed in, it changes back..

Anyone got an idea why this is happening? Or maybe a better idea to show the properties of objects in objects in the propertygrid?


回答1:


To edit properties inside an object (this is what you see for example with the winform editor with properties like Font, or Padding, ... where you can "expand" the oject clicking on the 'plus' icon) , you can use the ExpandableObjectConverter class, like this:

[TypeConverter(typeof(ExpandableObjectConverter))]
public class Correspondence
{
...
}

and remove the Browsable(false) of course:

public Correspondence Correspondence
{
    get;
    set;
}


来源:https://stackoverflow.com/questions/6368646/editing-a-property-of-an-object-inside-an-object-in-propertygrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!