We help IT Professionals succeed at work.
Get Started

Deriving or simulating deriving from multiple classes

Declan Basile
Last Modified: 2019-03-27
In vb.net, I have a multiple user defined classes.  One is named "actextbox" and inherits the windows forms textbox.  Another is a user defined control named "opgTriState".  I want all of these classes to have a property called "acControlSource" that simply Sets and Gets the value of a private string variable.  All of the classes will have the same implementation for this property.  Also, I want all of the classes to have a method called "acBindControl".  In this case, each class needs to have its own implementation.  My questions are:

1.) Is there a way to define the implementation (i.e. set and get) and associated variable for the "acControlSource" property only once for all these classes and somehow have each class inherit the property even though some of the classes are already derived from another class?
2.) How can I define an upper level class that I could CType to it in code to get intellisense for the "acBindControl" method but that would call the appropriate implementation for the specific (derived) class when invoked even though some of the classes are already derived from another class?

Here is my code so far so you get the idea of what I'm trying to accomplish (note: there will eventually be more classes.  I'm trying to get rid of the case statement and put the specific data binding implementation within the classes:

        Dim cntrlType As Type
        Dim strControlSource As String
        Dim propInfo As PropertyInfo

        For Each cntrl As Control In Me.Controls
            cntrlType = cntrl.GetType
            propInfo = cntrlType.GetProperty("acControlSource")
            If propInfo IsNot Nothing Then
                strControlSource = propInfo.GetValue(cntrl)
                If strControlSource <> "" Then
                    Select Case cntrlType.Name
                        Case "acTextBox"
                            cntrl.DataBindings.Add("Text", das1, "Returns." & strControlSource)
                        Case "opgTriState"
                            cntrl.DataBindings.Add("opgValue", das1, "Returns." & strControlSource, True, DataSourceUpdateMode.Never, Nothing)
                            AddHandler CType(cntrl, opgTriState).PropertyChanged, AddressOf WriteValueOPG
                    End Select
                End If
            End If

Open in new window

Watch Question
Senior Developer
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE