Vb.net PropertyGrid ExpandableObjectConverter集合属性列表(共T个),带有构造函数和只读属性

Vb.net PropertyGrid ExpandableObjectConverter集合属性列表(共T个),带有构造函数和只读属性,vb.net,typeconverter,Vb.net,Typeconverter,我有一个在泛型列表中使用的类型,它有一个构造函数参数,即列表本身。 例如 用于T的实际类声明为: Class MyClass Private _Parent As MyCollection Private _Property1 As String Private _Property2 As String Public Sub New(Parent As MyCollection, Property1 As String) _Parent = Pa

我有一个在泛型列表中使用的类型,它有一个构造函数参数,即列表本身。 例如

用于T的实际类声明为:

Class MyClass
    Private _Parent As MyCollection
    Private _Property1 As String
    Private _Property2 As String

    Public Sub New(Parent As MyCollection, Property1 As String)
        _Parent = Parent
        Me.Property1 = Property1
    End Sub
    ...
    Public Property Property1 As String
        Get
            Return _Property1
        End Get
        Set(value As String)
            _Property1 = value
            Dim result As String = value
            For Each item in Parent
                If item Is Me Then
                    Exit For
                End If
                ...
            Next
            _Property2 = result
       End Set
    End Property

    Public ReadOnly Property Property2 As String
        Get
            Return _Property2
       End Get
   End Property
End Class
如何在PropertyGrid中实现这样的类型转换器。
我的父属性没有公开,因为我不在类本身之外使用它,并且我的属性2是只读的。因此,在运行时的PropertyGrid设计器中,我不希望看到父级,我确实希望看到Property2,但它应该是只读的。如果我根本不使用TypeConverter,情况就是这样,那么为什么当我使用TypeConverter时它不能像我希望的那样工作呢。如果没有typeconverter,添加新项将无法正常工作,至少我会收到一个错误,说“找不到类型'MyClass'上的构造函数”,因此我假设需要重写CreateInstance和GetCreateInstanceSupported方法。即使我为父属性创建属性并将Browsable属性设置为False,我的CreateInstance方法也没有找到父属性的位置,因为它不在PropertyValue中。如果相反地公开它并设置ReadOnly属性,它将被看到,并且它也是可编辑的,这是我不想要的。我的Property2也是一样,我不希望它在PropertyGrid中可编辑。只读似乎被忽略了。我的MyCollection类是否还需要一个TypeConverter,还是需要重写其他方法

好吧,看来我可能是在说显而易见的答案,因为我猜显而易见的答案总是被忽视。我不得不将我的列表作为一个全局变量公开。因此,在我的代码中,我说:

Class MyClass
    Private _Parent As MyCollection = Nothing
    ...
    Public Sub New()
    End Sub

    Private ReadOnly Property Parent As MyCollection
        Get
            If _Parent Is Nothing Then
                _Parent = Module1.GlobalParent
            End If
            Return _Parent
        End Get
    End Prpoerty
    ...
    Public Property Property1 As String
        Get
            Return _Property1
        End Get
        Set(value As String)
            _Property1 = value
            Dim result As String = value
            For Each item in Parent
                If item Is Me Then
                    Exit For
                End If
                ...
            Next
            _Property2 = result
       End Set
    End Property

    Public ReadOnly Property Property2 As String
        Get
            Return _Property2
       End Get
    End Property
    ...
End Class
也就是说,没有必要有一个自定义的类型转换器毕竟,幸运的是,我的模块,形式和类是在同一个项目,否则生活将是困难的

Class MyClass
    Private _Parent As MyCollection = Nothing
    ...
    Public Sub New()
    End Sub

    Private ReadOnly Property Parent As MyCollection
        Get
            If _Parent Is Nothing Then
                _Parent = Module1.GlobalParent
            End If
            Return _Parent
        End Get
    End Prpoerty
    ...
    Public Property Property1 As String
        Get
            Return _Property1
        End Get
        Set(value As String)
            _Property1 = value
            Dim result As String = value
            For Each item in Parent
                If item Is Me Then
                    Exit For
                End If
                ...
            Next
            _Property2 = result
       End Set
    End Property

    Public ReadOnly Property Property2 As String
        Get
            Return _Property2
       End Get
    End Property
    ...
End Class