【问题标题】:Editing a property of an object inside an object in PropertyGrid在 PropertyGrid 中的对象内编辑对象的属性
【发布时间】:2011-06-16 07:47:19
【问题描述】:

我正在尝试使用 propertygrid 制作一个可配置/可编辑的对象。 这一切都很顺利,除了对象内的对象。

我有一个名为“ContactInformation”的对象/类。在该对象内部,我有一个名为“Correspondence”的对象。

这就是该部分的外观:

[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; }
}

这样我可以在属性网格中显示对象内部的对象的属性/变量。

无论如何,当我现在编辑这些值并按 Enter 键或单击其他位置时,它不会保留我刚刚输入的值,而是变回原样..

有人知道为什么会这样吗?或者在 propertygrid 中的对象中显示对象的属性可能是一个更好的主意?

【问题讨论】:

  • 也许简单刷新一下 propertyGrid 就可以解决它。更改数据后的“propertyGrid.refresh()”。
  • 不,那没用..
  • @MichielMagendans,您在扩展器中成功编辑变量了吗?

标签: c# winforms class object propertygrid


【解决方案1】:

要编辑对象内部的属性(例如,使用带有字体或填充等属性的 winform 编辑器,您可以在其中单击“加号”图标“扩展”对象),您可以使用ExpandableObjectConverter 类,像这样:

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

当然要删除 Browsable(false):

public Correspondence Correspondence
{
    get;
    set;
}

【讨论】:

    猜你喜欢
    • 2012-04-12
    • 2012-05-15
    • 2015-05-23
    • 2016-06-12
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多