Click to See Complete Forum and Search --> : Setting BrowsableAttribute at run time


Chuck Bruce
October 12th, 2009, 04:35 PM
I have a PropertyGrid to display/edit my custom controls. There is one (for now) property that I want to selectively display (or not display) in the PropertyGrid based on the value of another Property in the control. I have found some code that "showed me how" to do it using Reflection, but when I set the specified property to "Browsable = false", NOTHING will show up in my PropertyGrid at all on subsequent invocations! So, it seems as if I am turning off the Browsable attribute for everything in the control!

Here is a link to the code that I found on the .NET :

http://www.dotnet247.com/247reference/msgs/6/30102.aspx

(I had to remove all of the spurious "3D" strings... don't know what that is all about!)

Any help, and especially a working example would be greatly appreciated!

MacBeath
August 26th, 2010, 07:15 AM
I had exactly the same symptom: the whole PropertyGrid went blank. In fact, the PropertyGrid also refused to show any more objects, when you set other valid objects to its SelectedObject property.

But then I discovered something that made it work! Just make sure the Browsable attribute *exists* in the property (value true or false; it doesn't matter, since you're going to overwrite it at runtime anyway).

Summary:
* No "browsable attribute" at all in the code itself -> propertygrid goes blank;
* "browsable attribute" exists in the code -> the runtime attribute assignment works beautifully.