Hello, I an using a property grid to display the various properties of my custom form which the user can then modify. When I set the selected object to my form, it works, but it display all the properties of the form, Is it possible for me to define which form properties I want to display?
+1
A:
You can use the Browsable attribute to prevent properties from being shown. Unfortunately, you cannot change built-in types. If you inherit, and the property is not virtual, you cannot change it. Use aggregation instead if you want that.
EDIT: actually, while the above it true, you can overload this behavior by specifying your own Attribute and setting the BrowsableAttributes property of the PropertyGrid class that you inherit from. This way, you have all the freedom you want.
[Browsable(true)]
public bool GreatBrowsableProperty { get; set; }
[Browsable(false)]
public bool NonBrowsableProperty { get; set; }
[MyOwnBrowsable]
public bool BrowsablePropertyMyOwn { get; set; }
To learn more about creating and using attributes, have a look here.
Abel
2010-09-02 20:50:23
Could you please elaborate about the best way to do that?
Serge
2010-09-02 20:58:01
@Serge: I just did, I was upgrading while you were typing your comment :)
Abel
2010-09-02 20:58:37