troubleshooting Question

Deriving or simulating deriving from multiple classes

Avatar of Declan Basile
Declan BasileFlag for United States of America asked on
Visual Basic.NET
4 Comments1 Solution61 ViewsLast Modified:
In, 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
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros