修改 PropertyGrid 和 TypeConverterAttribute 的默认行为
我正在使用属性网格来编辑项目集合等:
集合的默认行为提供了一个 + 按钮来编辑数组的每个成员。
我正在使用表单来编辑此字段,该字段已连接,但我想删除用户使用“扩展器”编辑数组的能力,
因此它看起来像这样:
UPDATE1:使 ProductIds 成为 IList 属性而不是 int[ ] 现在这样做:
-----------------!
UPDATE2:使 ProductIds 成为一个自定义类,例如
MyWrappedCollection : IEnumerable<int>
,它现在看起来像这样:
当然,它仍然显示 [+]但它不会扩展为任何内容(即当您单击它时消失)
I am using a property grid to edit, amongst other things, a collection of items:
The default behavior for a collection provides a + button to edit each member of the array.
I am using a Form to edit this field, which is already wired up but I want to remove the ability for the user to edit the array by using the 'expander'
So it would look like this:
UPDATE1: made ProductIds an IList property instead of int[ ]
Now does this:
-----------------!
UPDATE2: made ProductIds a custom class, eg
MyWrappedCollection : IEnumerable<int>
so it now looks like this:
Sure, it still shows [+] but it doesnt expand to anything (ie disappears when you click it)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
控制属性是否可扩展的属性是 TypeConverter。 ExpandableObjectConverter 是一个内置类,它提供了扩展属性并查看其自身属性的能力。我猜测默认情况下数组和集合使用此转换器来显示其中的内容。
您可以编写自己的 TypeConverter(它不继承自 ExpandableObjectConverter)并将其设置为属性上的属性以删除 +。
The attribute that controls whether a property is expandable or not is it's TypeConverter. The ExpandableObjectConverter is a built in class that provides the ability to expand a property and look at it's own. I am guessing by default that arrays and collections use this converter to display what is in them.
You can write your own TypeConverter which does not inherit from ExpandableObjectConverter and set it as an attribute on your property to remove the +.
默认情况下,集合使用
[...]
方法。也许您可以使用集合(例如列表)而不是数组。顺便问一下,您使用数组的具体原因是什么?
By default for a collection, it uses
[...]
method. May be you could use a collection (For example a List) instead of an array.By the way, any specific reason you use arrays?
您需要实现并应用 UITypeEditor。请参阅如何:实现 UI 类型编辑器
覆盖 GetEditStyle< UITypeEditor 的 /strong> 返回 Modal
You need to implement and apply a UITypeEdtitor. See How to: Implement a UI Type Editor
Override GetEditStyle of your UITypeEditor to return Modal