Please discuss the proper way to add an “index” (i.e. an Item method) to a collection class that is derived from CollectionBase. That part of the below code doesn’t work; even though it is nearly copied from VS.Net Help.
Also, is List a property of CollectionBase, where List is an object type?
Thanks,
John Maggiore
Public Class Fluid
Dim sName As String
Property Name() As String
Get
Name = sName
End Get
Set(ByVal str As String)
sName = str
End Set
End Property
‘Other stuff here.
End Class
Public Class FluidsCollection
Inherits System.Collections.CollectionBase
Sub Add(ByVal f As Fluid)
list.Add(f)
End Sub
Sub Remove(ByVal f As Fluid)
Dim idx As Long
idx = list.IndexOf(f)
list.RemoveAt(idx)
End Sub
Overrides Sub Clear()
list.Clear()
End Sub
ReadOnly Property Item(ByVal idx As Integer) As Fluid
Get
Return CType(list.Item(idx), Fluid) ‘ Not allowed???
End Get
End Property
End Class