Changing Browsable Attribute at Runtime (C#) -


i'm trying change browsable attribute of variable in 1 of classes @ runtime. class containing attribute looks this:

public class displaywalltype : walltype     {         [typeconverter(typeof(sheathingoptionsconverter))]         [browsable(false)]         public override sheathing sheathingtype { get; set; }          public displaywalltype(string passedname, string passedtype, bool passedmirrorable, distance passedheight, string passedstudpattern, distance passedstudspacing, vaporbarrier passedbarrier)             : base(passedname, passedtype, passedmirrorable, passedheight, passedstudpattern, passedstudspacing, passedbarrier)         {          }          /// <summary>         /// empty constructor xml serialization         /// </summary>         public displaywalltype()         {          }     } 

i set false sheathingtype because don't want attribute show in first form of application. however, want visible in second form have method change it

private void _makesheathingvisible(displaywalltype walltypetomakesheathingvisible)         {             propertydescriptor descriptor = typedescriptor.getproperties(walltypetomakesheathingvisible.gettype())["sheathingtype"];             browsableattribute attrib = (browsableattribute)descriptor.attributes[typeof(browsableattribute)];             fieldinfo isbrow = attrib.gettype().getfield("browsable", bindingflags.nonpublic | bindingflags.instance);             isbrow.setvalue(attrib, true);         } 

that method above takes displaywalltype object , ensures browsable set true. second form treeview combined property grid. treeview populated instances of displaywalltype , when 1 selected, passed method sheathingtype shows in propertiesgrid rest of properties parent class.

enter image description here

however, sheathingtype still not show property wrong approach have no idea what

you cannot browsable attribute 1 exact property except have typedescriptor explicit declaration. in case getfield("browsable") return fieldinfo properties , switch them visible true. same thing appear if have properties , set 1 browsable false - hide properties.

provide custom typedescriptor needed attributes or use solutions https://www.codeproject.com/articles/7852/propertygrid-utilities.


Comments