Click here to Skip to main content
15,893,337 members
Articles / Desktop Programming / Windows Forms

Add Custom Properties to a PropertyGrid

Rate me:
Please Sign up or sign in to vote.
4.94/5 (219 votes)
22 Aug 2006Apache6 min read 1.6M   27.8K   443  
Extend a PropertyGrid with an Item collection; easy customization of properties with custom editor, custom converter and databinding.
Namespace PropertyGridEx
    Public Class CustomPropertyCollectionSet
        Inherits System.Collections.CollectionBase

        Public Overridable Function Add(ByVal value As CustomPropertyCollection) As Integer
            Return MyBase.List.Add(value)
        End Function

        Public Overridable Function Add() As Integer
            Return MyBase.List.Add(New CustomPropertyCollection)
        End Function

        Default Public Overridable Property Item(ByVal index As Integer) As CustomPropertyCollection
            Get
                Return DirectCast(MyBase.List.Item(index), CustomPropertyCollection)
            End Get
            Set(ByVal value As CustomPropertyCollection)
                MyBase.List.Item(index) = value
            End Set
        End Property

        Public Overridable Function ToArray()
            Dim list As New ArrayList
            list.AddRange(MyBase.List)
            Return list.ToArray(GetType(CustomPropertyCollection))
        End Function

    End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Software Developer (Senior)
Italy Italy
I am 40 years old and I've been working with C++, Visual Basic .NET, C# and ASP.NET. I have a large experience in Industrial Automation solutions, but I've worked also as Web developer and DBA. I like to share knowledge and projects with other people.

Comments and Discussions