473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serializing custom component with a strongly typed collection property

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!
Nov 20 '05 #1
0 1452

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
12864
by: jamie_m_ | last post by:
I have a custom collection ... clFile that INHERITS from NameObjectCollectionBase the problem is, when I try to create an xmlserializer instance i get an error You must implement a default accessor on brWAP.clFile because it inherits from ICollectio I must be having a thick day because I dont have a clue what the error message means. (I have written a defaut property called ITEM in the clFile class 'Classes to abstract a FILE entity...
1
2888
by: Carl Gilbert | last post by:
Hi I am trying to serialize a collection of GUIDs by overriding the serialize function on a diagram component I am using. The following code sucessfully serializes a single GUID: Public Overloads Overrides Function Serialize(ByVal Key As Object) As String Dim objXML As New XmlDocument Dim objParent As XmlElement
1
1644
by: womber | last post by:
I am getting XML from a dataset that has been populated via a storedprocedure no schemas have been applied nor any relationships. But the correct table names have been given to match the table(s) equivalent business object(s). I have a custom collection that implements ICollection and IEnumerable. Here is the collection: Imports ERP.BusinessObjects Imports ERP.BusinessObjects.Helpdesk Imports ICTObjects.Collections
1
1444
by: Derrick | last post by:
Hello all; I have created a custom component, whose properties (let's call them myObjectA and an collection of myObjectB) I'm trying to set via a GUI. I have the GUI running after the user clicks a Designer Verb, and it gets the values for myObjectA and myObjectB correctly. The designer creates the code for myObjectA just fine, however I can't seem to get it to work for the Collection of myObjectB's. At first I had an arraylist of...
2
2060
by: Mark | last post by:
Assume you have a strongly typed collection of a class called Person. The strongly typed collection implements IEnumerable so it can be databound to a server control like a DataGrid. The Person class has several public properties like FirstName, LastName, and Gender. What steps would it take to allow the collection to be sorted in multiple ways when bound to a DataGrid? In the past, I used the sort property of a DataView containing a...
2
2444
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just fine. However, when attempting to assing default values as designtime in the propertygrid, nothing is working on the class object. I know that I am doing it wrong, any ideas what it is? Thanks in advance
2
3815
by: Eamon Millman | last post by:
Greetings, I'm fairly new to the new ASP.NET 2.0 controls and I'm trying to get the TreeView control to display some non-xml/sitemap data I want to have in a tree format. To accomplish this I have followed the sample code provided on the MSDN website for writing a custom HierarchicalDataSourceControl, HierarchicalDataSourceView, IHierarchicalEnumerable, and IHierarchyData implementations (their FileSystem example).
5
4232
by: Simon | last post by:
Hi all, I am writing a windows application using vb.net on the 1.1 framework. We have in the application, some strongly typed collections that have been written as classes that do not inherit from collection base, but use an internal collection, to hold the objects and then implement IEnumerator, see example below,
5
3485
by: Simon Woods | last post by:
Hi Does anyone know if there any dotnet software out there which converts a dataset into a collection of custom objects, programmatically i.e. actually creates the class structure and collection class on-the-fly based on the fields in the dataset and then creates and populates the classes and adds them into the collection. Thanks
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.