How to present a list of custom UserControl for selection in Design View

60 views Asked by At

Consider the below:

enter image description here

I am designing a File Explorer type UserControl Library. I have a user control called Viewer which are the black controls above (2 or them). It's constructed thus:

<Serializable>
Public Class Viewer
    Inherits UserControl

I also have a userControl called ExplorerManager which manages the different types of associated controls (Viewers, Treeviews and Navigator bars). It needs to hold collections of the different types of control - such as a list of Viewers (think tabbed explorer + split view).

Thus, I constructed ExplorerManager thusly:

Public Class ExplorerManager
    Inherits Component

    Private _linkedViewers As Collection(Of Viewer)
    Public Property LinkedViewers() As Collection(Of Viewer)
        Get
            Return _linkedViewers
        End Get
        Set(ByVal value As Collection(Of Viewer))
            _linkedViewers = value
        End Set
    End Property

I'm trying for as much Designer View compatibility as possible. What I'm wanting to achieve is when you click on "LinkedViewers" in the ExplorerManager1 PropertyGrid, you get presented with a list of the Viewers on the form. At the moment, you just get the standard collections editor allowing you to Add/Remove items (but it is blank on opening and it doesn't persist what you add).

I've scouted about and the closest I could find for guidance was this codeproject article. I could get this working, but sadly, it only works for Control not UserControls. I got a cast error saying it couldn't cast Viewer into Control (although this is puzzling as UserControl inherits control??)

Would really appreciate any help. Stuck fast.

0

There are 0 answers