views:

150

answers:

3

Hi,

I'm looking to hide/show properties depending on what selection the user makes in a drop. I am handling the event fine, but cannot actually make the correct properties disappear. The solutions I have found on line are mainly from 2005 and as I've had very little experience with it I thought I must be doing something wrong if hiding properties is this hard.

So far I have tried accessing the property once the event is handled but the ReadOnly and IsBrowsable properties are read only.

The propertygrid has a property BrowsableAttributes that takes an Attribute list but only works negatively and cannot do or - only and. Providing an attribute collection of ; category - 'test' and isbrowsable - true; returns those that match both and as I can't provide multiple AttributeCollections I cannot make the search specific enough to hide the necessary ones whilst leaving others visible.

I have been banging my head against a wall for the past couple of hours thinking there must be an easier way.

SO I need your help! Thanks, Tom

+1  A: 

Have you tried applying this attribute to a property:

[Browsable(false)]
public object SomeProperty{
}

In that way SomeProperty will not appear on the propertygrid.

Hope this helps, Best regards, Tom.

tommieb75
Yes that will work at first but I need to be able to disable/enable when the drop down value changes.
tgandrews
@Tom: Incidentally, did you know that you can apply a custom Description to the property ... '[Description("some description for SomeProperty")]'....
tommieb75
@Tom: No I didn't that might work. Thanks.
tgandrews
+2  A: 

To do what you want to do here, you'd need to implement ICustomTypeDescriptor on your class, which is what the PropertyGrid will use to query your class/object to find out what items to display in the PropertyGrid, how to edit them, what category/description they should have, etc.

It can get quite messy, but it seems that there's a pre-written set of helper classes for you on Code Project at http://www.codeproject.com/KB/grid/PropertyGridDynamicProp.aspx.

I'd started writing my own version of the code given at Code Project and after hitting a snag I did some googling and came up with the Code Project link. It looks like they've done a lot better than I was. I've downloaded the code and it seems to work quite well.

If it doesn't solve your problem, please let me know and I'll dig a bit deeper.

Paul Sainsbury
A: 

This is similar to this question, which some people may wish to cross reference, but this answer seems more complete.

rathkopf