views:

63

answers:

1

In System.Windows.Forms there are a PropertyGrid that displays properties of an attached object. Let's say MyTextBox : TextBox.

Now, I would like to display on it some MyTextBox properties, say only Size, Location and my custom property Date.

More that than, I would like to be able to change the real property names, say "Dimension", "Location" and "Starting Date".

I saw two projects on this subject : first and second, but first does not work well(for browsable properties), and the second seems to add an event for each property changes, this is not acceptable.

A: 

You should be able to hide them with a [Browsable(false)] attribute. If you want to change the name, you need to write your own TypeDescriptor as seen here

Jacob G
Yes, but I wrote about a TextBox. I can't override all TextBox's properties with Browsablefalse attribute.
serhio
My fault... I totally overlooked the base class. You can use the same technique in the CustomTypeDescriptor I listed to filter out the properties you want as well as change their names.
Jacob G
same technique (?).. hmm.. I tried the code it don't compile (undefined method GetFriendlyname in FriendlyNamePropertyDescriptor class) marked: "// replace with code to return a friendly name" but what should I replace there?
serhio
That's where your code would go to say "if this property is called Size, call it Dimension instead." As far as "same technique" I mean in the ICustomTypeDescriptor GetProperties method implementation, you can filter out the properties that you want to return.
Jacob G
so..., as I understand, I need a method with a big if else for each property name and its DisplayName... so this solution will not be universal, but for a component... maybe..
serhio
Well, there is a "DisplayName" attribute that you could use, but you would then need to decorate every property. So, yeah, this is component specific.
Jacob G