Group Properties into Categories

by admin on November 10, 2009

If you want to group your class / component / control properties into categories, such as Accessibility, Appearance, Behavior, Data, Design, etc., it’s very easy to accomplish. All you need is to put System.ComponentModel.Category attribute on top of a property:

View Code VBNET
 
    <Category("CoolCategory")> _
    Private categorizedPropertyValue As String
    Public Property CategorizedProperty() As String
        Get
            Return categorizedPropertyValue
        End Get
        Set(ByVal value As String)
            categorizedPropertyValue = value
        End Set
    End Property
View Code CSHARP
[Category("CoolCategory")]
private string categorizedPropertyValue;
public string CategorizedProperty {
    get { return categorizedPropertyValue; }
    set { categorizedPropertyValue = value; }
}

When displayed in a PropertyGrid control, your property will appear in a new category (”CoolCategory” in this example). This feature is compatible with any .NET language, including VB.NET and C#.

Leave a Comment

Previous post: Use WIA to retrieve images from scanner, digital camera or webcam using VB.NET and C#.

Next post: Speed up your Visual Studio 2008!