Hi all,
I would like to create something that should be fairly simple I guess,
but I just might be taking a wrong road here or just don't know where
to look for an answer. Please enlighten me!
My wish:
Two controls:
First one (inherits Label) has a property with wich you can select any
of the available Controls type Two on the same form. I would like to
keep a reference to the control(Two) selected so when it changes name,
my property(of ControlOne) will also change. I've been going bakc and
forth, but my solution does not work. The controls will be linked in
designtime, but not runtime. Furthermore, after running a test, my
propertysetting is gone.
My implementation so far:
The typeconverter for the property seems to work as it lists all
ControlTwo types on the same form and lets me select it. I'll leave
that code out for now.
Public Class ControlOne
Inherits Label
Private m_objTwo As ControlTwo
Public Sub New()
Me.BackColor = Color.LightCoral
End Sub
<NotifyParentProperty(True), TypeConverter(GetType(QDataList)),
Bindable(False)> _
Property pControlTwo() As String
Get
Try
If m_objTwo Is Nothing Then
pControlTwo = ""
Me.BackColor = Color.LightCoral
Else
pControlTwo = m_objTwo.Site.Name
End If
Catch ex As Exception
pControlTwo = ""
Me.BackColor = Color.LightCoral
End Try
End Get
Set(ByVal value As String)
Dim objComponent As Component
Try
For Each objComponent In Container.Components
If objComponent.Site.Name.Equals(value) Then
m_objTwo = objComponent
Text = "Linked to " & objComponent.Site.Name
Me.BackColor = Color.Transparent
End If
Next
Catch ex As Exception
Text = "Not linked"
End Try
End Set
End Property
End Class
Any directions will be appreciated, greets,
Marcel