Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Property Grid - Browsable Attributes

Property Grid - Browsable Attributes

Scheduled Pinned Locked Moved C#
csshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tulika Shrivastava
    wrote on last edited by
    #1

    :confused:hi i have a program where I want to change the value of BrowsableAttributes.The problem is like this: I have a property called Simulation which can have values either On or Off.If it is On i want to show property called OnText along with other properties and hide OffText property and if is Off i want to hide OnText and show OffText along with the common properties. For this i feel i have to change the value of BrowsableAttributes.but it doesn't allow me to do so as it is readonly. Kindly suggest me a way to get around this problem. thanks Tulika Shrivastava

    M 1 Reply Last reply
    0
    • T Tulika Shrivastava

      :confused:hi i have a program where I want to change the value of BrowsableAttributes.The problem is like this: I have a property called Simulation which can have values either On or Off.If it is On i want to show property called OnText along with other properties and hide OffText property and if is Off i want to hide OnText and show OffText along with the common properties. For this i feel i have to change the value of BrowsableAttributes.but it doesn't allow me to do so as it is readonly. Kindly suggest me a way to get around this problem. thanks Tulika Shrivastava

      M Offline
      M Offline
      microsoc
      wrote on last edited by
      #2

      hi! :) try to implement the ICustomTypeDescriptor interface on your control. then in the GetProperties overloaded methods, iterate all the properties then set the new attributes you want depending on your condition. here's an example: //custom method to prevent redundant statement private PropertyDescriptorCollection x_HideShowProperties(PropertyDescriptorCollection baseProps) { PropertyDescriptor[] props = null; for (int i = 0; i < baseProps.Count; i++) { if (/*condition here*/) { if (props == null) { props = new PropertyDescriptor[baseProps.Count]; baseProps.CopyTo(props, 0); } props[i] = TypeDescriptor.CreateProperty( this.GetType(), baseProps[i], new BrowsableAttribute(false), new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)); } } if (props == null) { return baseProps; } else { return new PropertyDescriptorCollection(props); } } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { return x_HideShowProperties(TypeDescriptor.GetProperties(this, true)); } public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { return x_HideShowProperties(TypeDescriptor.GetProperties(this, attributes, true)); } then on your property(Simulation), add the attribute "RefreshProperties(RefreshProperties.All)". this will refresh the propertygrid. if your not yet familiar on this interface, just try to research it on the msdn or other .net help sites. hope that helps. :) microsoc

      T 1 Reply Last reply
      0
      • M microsoc

        hi! :) try to implement the ICustomTypeDescriptor interface on your control. then in the GetProperties overloaded methods, iterate all the properties then set the new attributes you want depending on your condition. here's an example: //custom method to prevent redundant statement private PropertyDescriptorCollection x_HideShowProperties(PropertyDescriptorCollection baseProps) { PropertyDescriptor[] props = null; for (int i = 0; i < baseProps.Count; i++) { if (/*condition here*/) { if (props == null) { props = new PropertyDescriptor[baseProps.Count]; baseProps.CopyTo(props, 0); } props[i] = TypeDescriptor.CreateProperty( this.GetType(), baseProps[i], new BrowsableAttribute(false), new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)); } } if (props == null) { return baseProps; } else { return new PropertyDescriptorCollection(props); } } PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { return x_HideShowProperties(TypeDescriptor.GetProperties(this, true)); } public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { return x_HideShowProperties(TypeDescriptor.GetProperties(this, attributes, true)); } then on your property(Simulation), add the attribute "RefreshProperties(RefreshProperties.All)". this will refresh the propertygrid. if your not yet familiar on this interface, just try to research it on the msdn or other .net help sites. hope that helps. :) microsoc

        T Offline
        T Offline
        Tulika Shrivastava
        wrote on last edited by
        #3

        hi:) thanx a lot it solved my problem

        M 1 Reply Last reply
        0
        • T Tulika Shrivastava

          hi:) thanx a lot it solved my problem

          M Offline
          M Offline
          microsoc
          wrote on last edited by
          #4

          nice to hear that! :) happy coding! :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups