They were right and I was wrong. Here is an example that will work in VB.
Imports System.ComponentModel
Public Class DataHolder
Public Sub Load()
Dim v As New MyCollectionItem()
v.Data = "First Element"
Me.mArray.Add(v)
v = New MyCollectionItem()
v.Data = "Second Element"
Me.mArray.Add(v)
End Sub
Public Function GetXML()
Dim serializer As New
System.Xml.Serialization.XmlSerializer(GetType(DataHolder))
Dim writer As New System.IO.StringWriter()
Dim Obj As DataHolder
Obj = Me
serializer.Serialize(writer, Obj)
Dim s As String
s = writer.ToString
Console.Write(s)
writer.Close()
Return s
End Function
Dim mArray As New MyCollectionClass()
<Xml.Serialization.XmlArray(), _
Xml.Serialization.XmlArrayItem(GetType(MyCollectionItem))> _
Public Property Array() As MyCollectionClass
Get
Return mArray
End Get
Set(ByVal Value As MyCollectionClass)
mArray = Value
End Set
End Property
End Class
Public Class MyCollectionClass
Inherits CollectionBase
Implements IBindingList
Default Public Overridable Shadows Property Item(ByVal index As Integer) As
MyCollectionItem
Get
Return CType(MyBase.List(index), MyCollectionItem)
End Get
Set(ByVal Value As MyCollectionItem)
MyBase.List(index) = Value
End Set
End Property
Public Function IndexOf(ByVal obj As MyCollectionItem) As Integer
Return List.IndexOf(obj)
End Function
Public Sub Add(ByVal obj As MyCollectionItem)
MyBase.List.Add(obj)
End Sub
Public Function AddNew() As Object Implements IBindingList.AddNew
Dim X As New MyCollectionItem()
list.Add(X)
Return X
End Function
Public ReadOnly Property AllowEdit() As Boolean Implements IBindingList.AllowEdit
Get
Return True
End Get
End Property
Public ReadOnly Property AllowNew() As Boolean Implements IBindingList.AllowNew
Get
Return True
End Get
End Property
Public ReadOnly Property AllowRemove() As Boolean Implements
IBindingList.AllowRemove
Get
Return True
End Get
End Property
Public Event ListChanged As ListChangedEventHandler Implements
IBindingList.ListChanged
Friend Sub OnListChanged(ByVal args As ListChangedEventArgs)
RaiseEvent ListChanged(Me, args)
End Sub
Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As
Object)
OnListChanged(New ListChangedEventArgs(ListChangedType.ItemDeleted, index))
End Sub
Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As
Object)
OnListChanged(New ListChangedEventArgs(ListChangedType.ItemAdded, index))
End Sub
Sub AddIndex(ByVal prop As PropertyDescriptor) Implements IBindingList.AddIndex
Throw New NotSupportedException()
End Sub
Sub ApplySort(ByVal prop As PropertyDescriptor, ByVal direction As
ListSortDirection) Implements IBindingList.ApplySort
Throw New NotSupportedException()
End Sub
Function Find(ByVal prop As PropertyDescriptor, ByVal key As Object) As Integer
Implements IBindingList.Find
Throw New NotSupportedException()
End Function
Sub RemoveIndex(ByVal prop As PropertyDescriptor) Implements
IBindingList.RemoveIndex
End Sub
Sub RemoveSort() Implements IBindingList.RemoveSort
End Sub
ReadOnly Property IsSorted() As Boolean Implements IBindingList.IsSorted
Get
End Get
End Property
ReadOnly Property SortDirection() As ListSortDirection Implements
IBindingList.SortDirection
Get
End Get
End Property
ReadOnly Property SortProperty() As PropertyDescriptor Implements
IBindingList.SortProperty
Get
End Get
End Property
ReadOnly Property SupportsChangeNotification() As Boolean Implements
IBindingList.SupportsChangeNotification
Get
Return True
End Get
End Property
ReadOnly Property SupportsSearching() As Boolean Implements
IBindingList.SupportsSearching
Get
Return False
End Get
End Property
ReadOnly Property SupportsSorting() As Boolean Implements
IBindingList.SupportsSorting
Get
Return False
End Get
End Property
End Class
Public Class MyCollectionItem
Implements System.ComponentModel.IEditableObject
Public Sub BeginEdit() Implements System.ComponentModel.IEditableObject.BeginEdit
End Sub
Public Sub CancelEdit() Implements System.ComponentModel.IEditableObject.CancelEdit
End Sub
Public Sub EndEdit() Implements System.ComponentModel.IEditableObject.EndEdit
End Sub
Dim mData As String
Public Property Data() As String
Get
Return mData
End Get
Set(ByVal Value As String)
mData = Value
End Set
End Property
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(24, 32)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 109)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim X As New DataHolder()
X.Load()
MsgBox(X.GetXML)
End Sub
End Class
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.