CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2001
    Posts
    77

    Setting BrowsableAttribute at run time

    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!

  2. #2
    Join Date
    Aug 2010
    Posts
    1

    Re: Setting BrowsableAttribute at run time

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured