2011-06-16 108 views
1

我正在尝试使用propertygrid进行可配置/可编辑的对象。 除了对象内部的对象,这一切都很顺利。编辑PropertyGrid中的对象内的对象的属性

我有一个名为“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; } 
} 

这样我可以显示属性的对象内的对象/变量,PropertyGrid中。

无论如何,当我现在编辑的值,然后按回车,或者点击其他地方,而不是保持它的价值我刚才输入,它变回..

任何人有一个想法,为什么这种情况正在发生?或者,也许更好的主意,以显示在propertygrid中的对象的属性?

+0

也许PropertyGrid中的一个简单的刷新将解决这个问题。 '改变数据后的'propertyGrid.refresh()'。 – Samidjo 2011-06-16 08:07:33

+0

不,没有工作.. – 2011-06-16 08:56:25

+0

@MichielMagendans,你是否成功地在扩展器中编辑变量? – 2013-04-11 09:41:01

回答

4

要编辑对象内部的属性(这就是您看到的例如使用类似于Font或Padding等属性的Winform编辑器,您可以在其中单击“加号”图标“展开”该对象)你可以使用ExpandableObjectConverter类,像这样:

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

并取出可浏览课程(假):

public Correspondence Correspondence 
{ 
    get; 
    set; 
} 
+0

+1 Spot on !! :) – MattDavey 2011-06-17 08:07:06