PropertyGrid: CategoryAttribute + BrowsableAttributes

M

Marco Segurini

Hi All,

I have a form containing only a PropertyGrid that I use to modify an
instance of the following class:

class MyClass
{
Point _point = new Point();

[CategoryAttribute("Drawing")]
public Point MyPoint
{
get { return _point; }
set { _point = value; }
}
}

All works fine.

Now if I add

this._propertyGrid.BrowsableAttributes
= new AttributeCollection(
new Attribute[] { new CategoryAttribute("Drawing") });

to the form's initialization code: what happens is that "MyPoint"
property does not more expand in the PropertyGrid.

Is there a way to apply the CategoryAttribute only to the first level of
properties?

TIA.
Marco.
 
V

VisualHint

Hello Marco,

I guess that you are trying to show only properties (and their
subproperties) that are under a particular category. Unfortunately you
are not using the right tool to do that. Your subproperties get
filtered because they don't have the CategoryAttribute you supply. A
better way would be to use a TypeDescriptor or TypeConverter for your
class that would filter out any toplevel property that is not under
the category (it would publish only the PropertyDescriptors that have
the CategoryAttribute).

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart FieldPackEditor.Net / DateTimePicker replacement (http://
www.visualhint.com/index.php/fieldpackeditor)
Home of Smart PropertyGrid for .Net and MFC (http://www.visualhint.com/
index.php/propertygrid)
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
 
N

Nicholas Paldino [.NET/C# MVP]

Marco,

Unfortunately, no. You would have to apply the appropriate attributes
to your parent class (which I can see you not wanting to do, for obvious
reasons).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top