maybe something like this would work (modify the item class to suit your
needs and fix the line wrapping...there's enough here to give you and idea):
Public Class Item
#Region " variables "
Private myKey As String
Public myText As String
#End Region
#Region " properties "
Public ReadOnly Property Key() As String
Get
Return myKey
End Get
End Property
Public ReadOnly Property Text() As String
Get
Return myText
End Get
End Property
#End Region
#Region " methods "
Public Sub New(Optional ByVal Key As String = Nothing, Optional ByVal
Text As String = Nothing)
If Key Is Nothing Then Key = ""
If Text Is Nothing Then Text = ""
If Key.Trim = "" Then Key = ""
If Text.Trim = "" Then Text = ""
myKey = Key
myText = Text
End Sub
Public Overrides Function ToString() As String
Dim serialized As String = myKey
If Not myKey = "" Then serialized = myKey
If Not serialized = "" AndAlso Not myText = "" Then serialized &= " "
If Not myText = "" Then serialized &= myText
Return serialized
End Function
#End Region
End Class
Public Class ItemArray
#Region " interfaces "
Implements IEnumerable
#End Region
#Region " events "
Public Event ItemAdded(ByVal Item As Item)
Public Event ItemsCopied()
Public Event ItemsCleared()
Public Event ItemRemoved()
#End Region
#Region " variables "
Private myItemArray() As Item
#End Region
#Region " properties "
Public ReadOnly Property Count() As Integer
Get
If myItemArray Is Nothing Then Return 0
Return myItemArray.Length
End Get
End Property
Default Public Overloads ReadOnly Property Item(ByVal Id As String) As
Item
Get
If myItemArray Is Nothing Then Return Nothing
Dim i As Item
For Each i In myItemArray
If i.Key = Id Then Return i
Next
Return Nothing
End Get
End Property
Default Public Overloads ReadOnly Property Item(ByVal Index As Integer)
As Item
Get
On Error Resume Next
If Index < 0 Then Return Nothing
If Index > myItemArray.GetUpperBound(0) Then Return Nothing
Return myItemArray(Index)
End Get
End Property
#End Region
#Region " methods "
Public Overloads Sub Add(ByVal Item As Item)
Dim index As Integer = 0
If Not myItemArray Is Nothing Then index = myItemArray.Length
ReDim Preserve myItemArray(index)
myItemArray(index) = Item
RaiseEvent ItemAdded(Item)
End Sub
Public Overloads Sub Add(ByVal Text As String)
Dim index As Integer = 0
If Not myItemArray Is Nothing Then index = myItemArray.Length
ReDim Preserve myItemArray(index)
Dim item As New item(Text:=Text)
myItemArray(index) = Item
RaiseEvent ItemAdded(Item)
End Sub
Public Overloads Function Copy() As ItemArray
Dim destination As New ItemArray
If myItemArray Is Nothing Then Return destination
Dim item As item
For Each item In myItemArray
destination.Add(item)
Next
Return destination
End Function
Public Overloads Sub Copy(ByVal Source As ItemArray)
Dim item As item
For Each item In Source
Me.Add(item)
Next
RaiseEvent ItemsCopied()
End Sub
Public Sub Clear()
myItemArray = Nothing
RaiseEvent ItemsCleared()
End Sub
Public Function GetEnumerator() As IEnumerator Implements
IEnumerable.GetEnumerator
Return New ItemArrayEnumerator(myItemArray)
End Function
Public Overloads Sub Remove(ByVal Key As String)
If myItemArray Is Nothing Then Return
Dim index As Integer
Dim item As item
Dim itemIndex As Integer = -1
For Each item In myItemArray
If item.Key = Key Then
itemIndex = index
Exit For
End If
index += 1
Next
If itemIndex = -1 Then Return
If itemIndex > myItemArray.GetUpperBound(0) Then Return
Remove(itemIndex)
End Sub
Public Overloads Sub Remove(ByVal Index As Integer)
If myItemArray Is Nothing Then Return
If Index = -1 OrElse Index > myItemArray.GetUpperBound(0) Then Return
If Index < myItemArray.GetUpperBound(0) Then
Array.Copy(myItemArray, Index + 1, myItemArray, Index,
myItemArray.GetUpperBound(0) - 1)
End If
Array.Clear(myItemArray, myItemArray.GetUpperBound(0), 1)
RaiseEvent ItemRemoved()
End Sub
#End Region
#Region " internal classes "
Private Class ItemArrayEnumerator
#Region " interfaces "
Implements IEnumerator
#End Region
#Region " variables "
Private myItemArray() As Item
Private myItemIndex As Integer = -1
#End Region
#Region " properties "
Public ReadOnly Property Current() As Object Implements
System.Collections.IEnumerator.Current
Get
Return DirectCast(myItemArray(myItemIndex), Item)
End Get
End Property
#End Region
#Region " methods "
Public Sub New(ByVal Items As Item())
myItemArray = Items
End Sub
Public Function MoveNext() As Boolean Implements
System.Collections.IEnumerator.MoveNext
myItemIndex += 1
If myItemArray Is Nothing Then Return False
Return myItemIndex < myItemArray.Length
End Function
Public Sub Reset() Implements System.Collections.IEnumerator.Reset
myItemIndex = -1
End Sub
#End Region
End Class
#End Region
End Class