How to make composite User Control VB.NET

Viewed 118
<Serializable()>    
Public Class PersonNameOnly
   
    Private p_Name As String = ""
    Public Sub New()
        ' needed for deserialization
    End Sub

    Public Property Name As String
        Get
            Return p_Name
        End Get
        Set(value As String)
            p_Name = value
        End Set
    End Property
End Class 

[WinForm]

The PersonNameOnly Class above is bonded Type of BindingSource on the PersonUsercontrolForPersonWithNameOnly user control, the name is bonded to a Textbox.

MainUsercontrolForPersonWithNameOnly has a collection of the PersonUsercontrolForPersonWithNameOnly

All the Above Works Fine in the Existing app.

I need new to create a new Form MainUsercontrolForPersonWITHIMAGE So I have created a new UserControl that inherits PersonUsercontrolForPersonWithNameOnly and added a Label that holds the ImageUrl, so This is what I've done so far below.

<Serializable()>
Public Class PersonWITHIMAGE
    Inherits PersonNameOnly
    Private p_ImageUrl As String = ""
    Public Sub New()
        ' needed for deserialization
    End Sub

    Public Property ImageUrl As String
        Get
            Return p_ImageUrl
        End Get
        Set(value As String)
            p_ImageUrl = value
        End Set
    End Property
End Class 

[WinForm]

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class PersonUsercontrolForPersonWITHIMAGE 
    Inherits PersonUsercontrolForPersonWithNameOnly 

How Can I Merge the two data binding as if it was one source, I manage to get the Name only to work on the top-level form with the collection but am not sure how to merge the data in sync with the name only User Control.

How Can I merge the two data binding in once composite form?

1 Answers

You seem to be wanting to bind to two different types, of which one is a base type of the other. I don't think you can do that.

But have you looked at using an interface, eg IPersonUsercontrolForPerson and basing each class on it? This should open up the possibility of abstracting your control binding.

Disclaimer! This answer should act as a jumping-off point as I haven't actually coded up a test/answer for you. But that's where I'd start looking.

Related