ICustomTypeDescriptor Implementation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allan Bredahl

    #1

    ICustomTypeDescriptor Implementation

    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 ICustomTypeDesc riptor
    interface so I can make my own GetProperties method.


    I have constructed my own derived PropertyDescrip tor class which I try to
    use istead of the default propertydescrip tor 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 GBPropertyDescr iptor

    Inherits System.Componen tModel.Property Descriptor

    Private _DisplayName As String
    Private _BaseProperty As System.Componen tModel.Property Descriptor

    Public Sub New(ByVal BaseProperty As
    System.Componen tModel.Property Descriptor, ByVal Name As String, ByVal
    DisplayName As String, ByVal Attrs() As System.Attribut e)

    MyBase.new(Name , Attrs)
    Me._BasePropert y = 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 PropertyDescrip tors of the class so I can pass this
    to the constructor of my derived PropertyDescrip tor class.

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

    Public Function GetProperties(B yVal attributes() As System.Attribut e) As
    System.Componen tModel.Property DescriptorColle ction Implements
    System.Componen tModel.ICustomT ypeDescriptor.G etProperties

    Dim properties As System.Componen tModel.Property DescriptorColle ction
    Dim prop As System.Componen tModel.Property Descriptor
    Dim NewPropertyDesc riptor As GBPropertyDescr iptor
    Dim MyPropertyColle ction As ArrayList
    Dim PropArray As System.Componen tModel.Property Descriptor()

    properties = 'thisclass.GetT heREalPropertie s' <------ THIS IS THE REAL
    PROBLEM

    For Each prop In properties
    NewPropertyDesc riptor = New GBPropertyDescr iptor(prop, "RealName",
    "DisplayNam e", attributes)
    MyPropertyColle ction.Add(NewPr opertyDescripto r)
    Next

    PropArray = MyPropertyColle ction.ToArray
    Return New PropertyDescrip torCollection(P ropArray)

    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


Working...