I make a similar post in another newsgroup, but this example is
simplified somewhat.
I have a component (cmpMyComponent ) with 2 properties. The 1st property
is a string value (Description) and the 2nd property is a strongly typed
collection class (myCollectionPr operty).
The collection contains a simple class (myCustomClass) which has 1 text
property (TextProperty).
Editing the properties for the component in the windows forms designer
works fine, but compiling the application causes the collection property
to lose its values. I assume this is because the component's collection
property isn't being serialized to the the myForm.resx file
automatically.
I've tried setting a <serializable > attribute on the component, as well
as the
<DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content
)> attribute on the collection property in the component.
Below is the sample project code. Help is greatly appreciated.
'// THIS IS THE COMPONENT
Public Class myComponent
Inherits System.Componen tModel.Componen t
Private m_strDescriptio n As String
Private m_myCollectionP roperty As myCustomClassCo llection
#Region " Component Designer generated code "
Public Sub New(ByVal Container As System.Componen tModel.IContain er)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(M e)
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Component overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Component Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r
End Sub
#End Region
<DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content
)> _
Public Property myCollectionPro perty() As
myCustomClassCo llection
Get
Return m_myCollectionP roperty
End Get
Set(ByVal Value As myCustomClassCo llection)
m_myCollectionP roperty = Value
End Set
End Property
Public Property Description() As String
Get
Return m_strDescriptio n
End Get
Set(ByVal Value As String)
m_strDescriptio n = Value
End Set
End Property
End Class
'// THIS IS THE COLLECTION AND CUSTOM CLASS
<Serializable() > _
Public Class myCustomClassCo llection
Inherits System.Collecti ons.CollectionB ase
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal myCValue As myCustomClassCo llection)
MyBase.New()
Me.AddRange(myC Value)
End Sub
Public Sub New(ByVal myCValue() As myCustomClass)
MyBase.New()
Me.AddRange(myC Value)
End Sub
Default Public Property Item(ByVal intIndex As Integer) As
myCustomClass
Get
Return CType(List(intI ndex), myCustomClass)
End Get
Set(ByVal Value As myCustomClass)
List(intIndex) = value
End Set
End Property
Public Function Add(ByVal myCValue As myCustomClass) As Integer
Return List.Add(myCVal ue)
End Function
Public Overloads Sub AddRange(ByVal myCValue() As myCustomClass)
Dim intCounter As Integer = 0
Do While (intCounter < myCValue.Length )
Me.Add(myCValue (intCounter))
intCounter = (intCounter + 1)
Loop
End Sub
Public Overloads Sub AddRange(ByVal myCValue As
myCustomClassCo llection)
Dim intCounter As Integer = 0
Do While (intCounter < myCValue.Count)
Me.Add(myCValue (intCounter))
intCounter = (intCounter + 1)
Loop
End Sub
Public Function Contains(ByVal myCValue As myCustomClass) As Boolean
Return List.Contains(m yCValue)
End Function
Public Sub CopyTo(ByVal myCArray() As myCustomClass, ByVal intIndex
As Integer)
List.CopyTo(myC Array, intIndex)
End Sub
Public Function IndexOf(ByVal myCValue As myCustomClass) As Integer
Return List.IndexOf(my CValue)
End Function
Public Sub Insert(ByVal intIndex As Integer, ByVal myCValue As
myCustomClass)
List.Insert(int Index, myCValue)
End Sub
Public Shadows Function GetEnumerator() As myCustomClassEn umerator
Return New myCustomClassEn umerator(Me)
End Function
Public Sub Remove(ByVal myCValue As myCustomClass)
List.Remove(myC Value)
End Sub
End Class
Public Class myCustomClassEn umerator
Inherits Object
Implements System.Collecti ons.IEnumerator
Private iEnBase As System.Collecti ons.IEnumerator
Private iEnLocal As System.Collecti ons.IEnumerable
Public Sub New(ByVal myCMappings As myCustomClassCo llection)
MyBase.New()
Me.iEnLocal = CType(myCMappin gs, System.Collecti ons.IEnumerable )
Me.iEnBase = iEnLocal.GetEnu merator
End Sub
Public ReadOnly Property Current() As myCustomClass
Get
Return CType(iEnBase.C urrent, myCustomClass)
End Get
End Property
ReadOnly Property System_Collecti ons_IEnumerator _Current() As Object
Implements System.Collecti ons.IEnumerator .Current
Get
Return iEnBase.Current
End Get
End Property
Public Function MoveNext() As Boolean
Return iEnBase.MoveNex t
End Function
Function System_Collecti ons_IEnumerator _MoveNext() As Boolean
Implements System.Collecti ons.IEnumerator .MoveNext
Return iEnBase.MoveNex t
End Function
Public Sub Reset()
iEnBase.Reset()
End Sub
Sub System_Collecti ons_IEnumerator _Reset() Implements
System.Collecti ons.IEnumerator .Reset
iEnBase.Reset()
End Sub
End Class
Public Class myCustomClass
Private m_strTextProper ty As String
Public Property TextProperty() As String
Get
Return m_strTextProper ty
End Get
Set(ByVal Value As String)
m_strTextProper ty = Value
End Set
End Property
End Class
=============== =
Jordan Bowness
=============== =
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!