Question about the TypeDescriptor.GetProperties() method. RRS feed

  • Question

  • Hi,

    I am using a PropertyGrid to display properties of objects. These implement the ICustomTypeDescriptor interface.
    When such an object is assigned to the PropertyGrid's SelectedObject property the following method is called.

    Code Snippet

    public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this, attributes, true);
        return properties;

    When this happens attributes contains the BrowsableAttribute with it's Browsable attribute set to true. : )
    As far as I understood the filtering rules I'd expect the returned PropertyDescriptorCollection to contain all properties except the ones that have the [Browsable(false)] attribute applied to them.
    That would be exactly what I'd like to do.

    In fact the returned collection contains all the properties.

    What is my mistake?

    Thanks in advance.
    Thursday, March 6, 2008 10:50 PM


  • GetProperties filters only on properties having an attribute (e.g. in your case would be Browsable), but you have than to check if the value of the attribute is true or false.

    The following code sample is maybe doing what you want:
    Code Snippet
    foreach (PropertyDescriptor des in TypeDescriptor.GetProperties(this)) {

                    if (des.IsBrowsable) {

    Saturday, March 8, 2008 11:36 AM