C# Winforms:将项目添加到集合时 PropertyGrid 未更新
我有一个自定义类,可以通过 PropertyGrid
进行编辑。在该类中,我有一个自定义Collection
(带有自定义PropertyDescriptor
和TypeConverter
)。
可以使用默认的集合编辑器向集合
添加或删除项目。这一切都很好。但是 - 关闭集合编辑器后,PropertyGrid 不会更新。当我手动调用 PropertyGrid
上的 Refresh()
时,更改会反映在 PropertyGrid 中。
当集合编辑器关闭时,如何让 PropertyGrid 自动刷新?我之前寻求一个解决方案,我应该将 CollectionEditor 子类化(我似乎找不到)。
请帮忙。
I've got a custom class which can be edited through the PropertyGrid
. In that class I've got a custom Collection
(with custom PropertyDescriptor
and TypeConverter
).
Items can be added to or removed from the Collection
with the default Collection Editor. This all works fine. But - after closing the Collection Editor, the PropertyGrid is not updated. When I manual make a call to Refresh()
on the PropertyGrid
, the changes are reflected in the PropertyGrid.
How can I get the PropertyGrid to automatically refresh when the Collection Editor has been closed? I sought for a solution earlier where I should subclass CollectionEditor (which I can't seem to find).
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
插入自 http://msdn.microsoft.com/en- us/library/system.componentmodel.refreshpropertiesattribute.aspx
使用描述符添加属性
演练:在设计时调试自定义 Windows 窗体控件,网址为 http://msdn.microsoft.com/en-us/library/5ytx0z24.aspx
Inserted from http://msdn.microsoft.com/en-us/library/system.componentmodel.refreshpropertiesattribute.aspx
Adding Attribute with Descriptor
Walkthrough: Debugging Custom Windows Forms Controls at Design Time at http://msdn.microsoft.com/en-us/library/5ytx0z24.aspx
您还可以尝试将 NotifyParentProperty 属性添加到集合中。这在类似的情况下对我有用。
You might also try adding the NotifyParentProperty attribute to the collection. This has worked for me in similar situations.
在这种情况下我得到解决方案。
需要从 CollectionEditor 类派生并制作如下所示的自定义编辑器:
在主窗体中,我订阅自定义编辑器的静态事件。
问候, 阿尔乔姆
I get solution in this situation.
There is a need to derive from CollectionEditor class and make custom editor like this:
In main form I subscribe to static event of my custom editor.
Regards, Artem
我使用这个基类
然后你只需将你的集合编辑器基于它即可。当收集表单关闭时,它会自动刷新属性网格。
但请注意,这个解决方案反映在属性网格的内部,并且可以随时被破坏,但我已经这样做了一段时间了,没有任何问题
I use this base class
Then you just base your Collection editor on that. It will automatically refresh the property grid when the collection form is closed.
Be aware though, this solution is reflecting into the internals of the property grid and can be broken at any time, but i have done this for a while now with no problem
完美解决方案
perfect Solution