编辑PropertyGrid中对象内对象的属性 [英] Editing a property of an object inside an object in PropertyGrid

查看:550
本文介绍了编辑PropertyGrid中对象内对象的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个对象,可配置/可编辑的属性。
这一切都进行得很好,除了对象里面的对象。



我有一个名为ContactInformation的对象/类。在这个对象中,我有一个名为Correspondence的对象。



这是该部分的外观:

  [Browsable(false)] 
public通信函数
{
get;
set;
}
public int通信状态
{
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通信日期
{
get {return this.Correspondence.LastSend; }
set {this.Correspondence.LastSend = CorrespondenceDate; }
}

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



无论如何,当我编辑的值现在,并按enter键或单击其他地方,而不是保持它刚刚键入的值,



任何人都知道为什么会发生这种情况?

解决方案

要编辑对象中的属性(this是你看到的例如使用winform编辑器的属性,如Font,或Padding,...,你可以展开点击加号图标),你可以使用 ExpandableObjectConverter 类,如下所示:

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



并移除Browsable(false):

  public通信函授
{
get;
set;
}


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?

解决方案

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

这篇关于编辑PropertyGrid中对象内对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆