0

Is it possible to add/remove properties in a Windows Forms PropertyGrid control depending on the value of another boolean property?

As an example, suppose the selected object has a boolean ShowTitle property. I need to show TitleFont and TitleColor properties only if ShowTitle is set to true. Also, it would be great if the TitleFont and TitleColor properties were children of the ShowTitle property.

If this is not possible, then what other options do I have apart from creating a custom editor?

Update:

From what I understand, it seems that the PropertyGrid allows us to do this...

Expandable property

...but not this (below image is just a mock-up) ...

Dropdown (mock-up)

Agnel Kurian
  • 57,975
  • 43
  • 146
  • 217
  • What you could do is reuse the DynamicTypeDescriptor class described in my answer to this question here on SO: http://stackoverflow.com/questions/16422844/propertygrid-browsable-not-found-for-entity-framework-created-property-how-to-f – Simon Mourier Feb 13 '14 at 18:16
  • @Simon, I have updated my post. I am trying to achieve the second case, i.e. skip the first line of the expandable property grid item. – Agnel Kurian Feb 14 '14 at 09:32
  • PropertyGrid is very hardcoded on the edge... There are only a few things you can do on the displayed grid itself (UI Type editor are more flexible). A sub item is always a child of an item. – Simon Mourier Feb 14 '14 at 13:41
  • @SimonMourier, you can post your comments as answer so I can accept it. – Agnel Kurian Feb 14 '14 at 17:45
  • possible duplicate of [How do you control what is visible in a property grid at runtime?](http://stackoverflow.com/questions/13673101/how-do-you-control-what-is-visible-in-a-property-grid-at-runtime) – John Alexiou Feb 14 '14 at 20:38
  • @ja72, see the update at the end of the question. My requirement is to have a list of properties as children of a True/False dropdown. – Agnel Kurian Feb 15 '14 at 12:41
  • Which is exactly why this question is a duplicate. An the accepted answer is the same also. – John Alexiou Feb 15 '14 at 21:14
  • @ja72, Got it! I was looking at the wrong question. You are right. But the last part of my question "Also, it would be great if the TitleFont and TitleColor properties were children of the ShowTitle property" is also significant. – Agnel Kurian Feb 16 '14 at 04:52

1 Answers1

1

What you could do is reuse the DynamicTypeDescriptor class described in my answer to this question here on SO: PropertyGrid Browsable not found for entity framework created property, how to find it?

There is also another good one base ond the same utility class: Optimize class for PropertyGrid

Community
  • 1
  • 1
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298