开发者

Modify default behaviour of PropertyGrid and TypeConverterAttribute

I am using a property grid to edit, amongst other things, a collection of items:

Modify default behaviour of PropertyGrid and TypeConverterAttribute

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:

Modify default behaviour of PropertyGrid and TypeConverterAttribute

UPDATE1: made ProductIds an IList property instead of int[ ] Now does this:

Modify default behaviour of PropertyGrid and TypeConverterAttribute

-----------------!

UPDATE2: made ProductIds a custom class, eg

 MyWrappedCollection : IEnumerable<int&开发者_如何学编程gt;

so it now looks like this:

Modify default behaviour of PropertyGrid and TypeConverterAttribute

Sure, it still shows [+] but it doesnt expand to anything (ie disappears when you click it)


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?


You need to implement and apply a UITypeEdtitor. See How to: Implement a UI Type Editor

Override GetEditStyle of your UITypeEditor to return Modal

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜