Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Categories to the .NET PropertyGrid

Is it only possible to add categories to the .NET PropertyGrid by annotating my data class with attributes like CategoryAttribute?

like image 792
msfanboy Avatar asked Oct 14 '22 17:10

msfanboy


2 Answers

You can use the CategoryAttribute. The documentation states:

A new category can be created for any name by specifying the name of the category in the constructor for the CategoryAttribute.

Example:

[
Category("MyCategory"),
Description("Specifies something")
]
public string Something { //... }
like image 80
Klaus Byskov Pedersen Avatar answered Oct 20 '22 08:10

Klaus Byskov Pedersen


Doing this with ICustomTypeDescriptor and your own PropertyDescriptor class is quite easy and does not involve so much code.

This article Customized display of collection data in a PropertyGrid describes how to do this in detail. For adding categories you would also need to override the Category property in your PropertyDescriptor class.

like image 20
Peladao Avatar answered Oct 20 '22 08:10

Peladao