ICustomTypeDescriptor Implementation

  • Thread starter Thread starter Allan Bredahl
  • Start date Start date
A

Allan Bredahl

Hi all


I'm trying to make the properties of my classes show in the PropertyGrid
with a displayname that it gets from an attribute on the property instead of
showing the actual property name.

Therefore I'm trying to make my class implement the ICustomTypeDescriptor
interface so I can make my own GetProperties method.


I have constructed my own derived PropertyDescriptor class which I try to
use istead of the default propertydescriptor class. This consists of an
overridden displayname property and the Base Property to get to the rest of
the info on the property.


Public Class GBPropertyDescriptor

Inherits System.ComponentModel.PropertyDescriptor

Private _DisplayName As String
Private _BaseProperty As System.ComponentModel.PropertyDescriptor

Public Sub New(ByVal BaseProperty As
System.ComponentModel.PropertyDescriptor, ByVal Name As String, ByVal
DisplayName As String, ByVal Attrs() As System.Attribute)

MyBase.new(Name, Attrs)
Me._BaseProperty = BaseProperty
Me._DisplayName = DisplayName

End Sub

Public Overrides ReadOnly Property DisplayName() As String
Get
Return Me._DisplayName
End Get
End Property

.........
.........

End Class



I'm not shure if I have this class right, but my main problem i s the
GetProperties method itself:


I need to get the base PropertyDescriptors of the class so I can pass this
to the constructor of my derived PropertyDescriptor class.

something like This (Code is cinstructed by intuition not tested) :

Public Function GetProperties(ByVal attributes() As System.Attribute) As
System.ComponentModel.PropertyDescriptorCollection Implements
System.ComponentModel.ICustomTypeDescriptor.GetProperties

Dim properties As System.ComponentModel.PropertyDescriptorCollection
Dim prop As System.ComponentModel.PropertyDescriptor
Dim NewPropertyDescriptor As GBPropertyDescriptor
Dim MyPropertyCollection As ArrayList
Dim PropArray As System.ComponentModel.PropertyDescriptor()

properties = 'thisclass.GetTheREalProperties' <------ THIS IS THE REAL
PROBLEM

For Each prop In properties
NewPropertyDescriptor = New GBPropertyDescriptor(prop, "RealName",
"DisplayName", attributes)
MyPropertyCollection.Add(NewPropertyDescriptor)
Next

PropArray = MyPropertyCollection.ToArray
Return New PropertyDescriptorCollection(PropArray)

End Function


But how do I get the "Real" properties when I have just overridden the
method that get's them ??


Does anyone have some example code that can clear things up for me ? I feel
that I'm very close, but just can't get it right.



Thanks in advance


Allan Bredahl
 
Back
Top