C# 窗体 : PropertyGrid not updated when item added to Collection

标签 c# collections propertygrid

我有一个可以通过 PropertyGrid 编辑的自定义类。在该类中,我有一个自定义 Collection(带有自定义 PropertyDescriptorTypeConverter)。

可以使用默认的集合编辑器将项目添加到集合 或从中删除。这一切都很好。但是 - 关闭 Collection Editor 后,PropertyGrid 不会更新。当我在 PropertyGrid 上手动调用 Refresh() 时,更改会反射(reflect)在 PropertyGrid 中。

如何让 PropertyGrid 在 Collection Editor 关闭时自动刷新?我之前寻求过一个解决方案,我应该将 CollectionEditor 子类化(我似乎找不到)。

请帮忙。

最佳答案

RefreshPropertiesAttribute Class

Indicates that the property grid should refresh when the associated property value changes. This class cannot be inherited.

插入自 http://msdn.microsoft.com/en-us/library/system.componentmodel.refreshpropertiesattribute.aspx

添加带有描述符的属性

        Public Overrides ReadOnly Property Attributes() As System.ComponentModel.AttributeCollection
            Get
                Return New AttributeCollection(New Attribute() {RefreshPropertiesAttribute.Repaint})
            End Get
        End Property

演练:在设计时调试自定义 Windows 窗体控件 http://msdn.microsoft.com/en-us/library/5ytx0z24.aspx

关于C# 窗体 : PropertyGrid not updated when item added to Collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3014253/

相关文章:

java - 获取集合元素的最快方法是什么?

c# - 按名称访问 C# 代码资源字典的元素

c# - EF Core 3.1 如何在多对多关系中自动映射

powershell - System.Collections.ArrayList 变为 System.Collecits.HashTable

java - 如何显示带有字符串计数的字符串

c# - 对象级的 PropertyGrid 只读属性

c# - 如何在 PropertyGrid 中显示带有子类的对象

c# - 在 PropertyGrid C# 中显示 DebuggerDisplay

c# - 匹配正则表达式中的可选斜杠

c# - 数据库连接(最佳实践)