Question

I want to add attributes (like Browsable(false)) dynamically while displaying in the grid. Scenario is that I have a custom class with some public properties. However, I dont want all of the public properties to be displayed in the UI. Is there a way out?

I tried using TypeDescriptor. However, it works only at the type level and not at the property level. I couldn't find any help on how to use it at property-level.

Any pointers will be highly appreciated.

Was it helpful?

Solution

Actually It is possible, but I have to admit it is rather obscure and poorly documented. The key is to derive your own custom TypeDescriptorProvider from System.ComponentModel.TypeDescriptionProvider. Then you can return your own TypeDescriptor descendant.

I did this to fix a rather nasty limitation regarding ViewModels and metadata in ASP.NET MVC, but you can just as well use it to insert your own extra metadata.

OTHER TIPS

I have been working in this same area for the past few days. Long story short, I came to the conclusion this is not possible.

Is the reason you are attempting to apply attributes at runtime because you dont want to mix "UI" code with your custom classes?

If that is the case, the BrowsableAttribute is a member of the ComponentModel (http://msdn.microsoft.com/en-us/library/system.componentmodel.aspx) and is not UI related in the same sense as WinForms.

Karl

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top