我正在尝试使一个对象,可配置/可编辑的属性网格。这一切都很顺利,除了对象内部的对象。
我有一个名为"ContactInformation“的对象/类。在这个对象中,我有一个名为“通信”的对象。
这个部分看起来是这样的:
[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; }
}这样,我就可以在properties网格中显示对象内部的对象的属性/变量。
无论如何,当我现在编辑这些值,并按enter键,或者在其他地方单击时,它不会保留我刚刚输入的值,而是会更改回来。
有人知道为什么会发生这种事吗?或者,在properties网格中显示对象中对象的属性可能是一个更好的想法?
发布于 2011-06-17 14:18:42
要编辑对象内部的属性(这就是您在winform编辑器中看到的,它具有诸如Font或Padding...单击‘加号’图标可以“展开”对象),您可以使用ExpandableObjectConverter类,如下所示:
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Correspondence
{
...
}当然,删除可浏览的(False):
public Correspondence Correspondence
{
get;
set;
}https://stackoverflow.com/questions/6368646
复制相似问题