tags:

views:

39

answers:

1

I have a custom component, that contains a list of another components.

If I add a child component to the list, it shows up on the same level as the parent component in the document outline window.

How can I make it a subitem of the parent component? (similarly to e.g. TabPages that are subitems of a TabControl)

Here is my code:

Public Class SomeComponent
    Inherits Component

    Public Sub New(ByVal cont As IContainer)
        cont.Add(Me)
    End Sub

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    <Editor("System.ComponentModel.Design.CollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor))> _
    Public ReadOnly Property Items() As List(Of SomeOtherComponent)
        Get
            If _items Is Nothing Then
                _items = New List(Of SomeOtherComponent)
            End If
            Return _items
        End Get
    End Property
    Private _items As List(Of SomeOtherComponent) = Nothing

End Class

Public Class clsAction
    Inherits SomeOtherComponent

    Public Sub New()
    End Sub

    Public Sub New(ByVal cont As IContainer)
        cont.Add(Me)
    End Sub

    '...

End Class
A: 

I have found the solution, here are the changes to the original code:

<Designer(GetType(SomeComponentDesigner))> _
Public Class SomeComponent
...
End Class

'this hides SomeOtherComponent from the component tray
<DesignTimeVisible(False)> _
Public Class SomeOtherComponent
...
End Class

Public Class SomeComponentDesigner
    Inherits ComponentDesigner

    Public Overrides ReadOnly Property AssociatedComponents() As System.Collections.ICollection
        Get
            If TypeOf (Me.Component) Is SomeComponent Then
                Return DirectCast(Me.Component, SomeComponent).Items
            Else
                Return MyBase.AssociatedComponents
            End If
        End Get
    End Property

End Class
ondatra