Linda

Not sure if this is what your'e looking for, but here is a sample of my
collection classes - colComponents is my custom collection class of
clscomponent

JC

---------------------------------
Public Class colComponents
  Implements IEnumerable
  Private mobjColl As Collection

  Public Function GetEnumerator() As IEnumerator Implements
Enumerable.GetEnumerator
    Return mobjColl.GetEnumerator
  End Function


  Public ReadOnly Property Count() As Long
    Get
      Return mobjColl.Count
    End Get
  End Property

  Public Sub New()
    mobjColl = New Collection()
  End Sub

  Public Sub Add(ByVal pobj As clsComponent)
    Try
      If pobj.GID = "" Then 'Your primary key
        mobjColl.Add(pobj)
      Else
        mobjColl.Add(pobj, pobj.GID)
      End If
    Catch Ex As Exception
      Throw Ex
    End Try
  End Sub

  Public Function ItemByKey(ByVal pstrGID As String) As clsComponent
    Try
      Return CType(mobjColl.Item(pstrGID), clsComponent)
    Catch Ex As Exception
      Throw Ex
    End Try
  End Function

  Public Sub Reset()
    mobjColl = New Collection()
  End Sub

  Public Function Item(ByVal index As Integer) As clsComponent
    Try
      Return CType(mobjColl.Item(index), clsComponent)
    Catch Ex As Exception
      Throw Ex
    End Try
  End Function

End Class
---------------------------------

-----Original Message-----
From: Don & Linda [mailto:[EMAIL PROTECTED]]
Sent: 16 August 2002 09:36 PM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] using system.collections in .net

I am trying to implement my own collection class for an object in VB by
inheriting from System.Collection.CollectionsBase.  However, I would like to
use a key to insert my objects into the collection.  It looks like the add
method in the collectionsbase class has only the object as an argument.

Is there another class that I can inherit from that does what I need it to
do.

Ideally, I want to be able to do something like I used to be able to do in
vb6:

Public Sub Add(objItemToAdd As OrderDetail, _
               Optional Key As String = "", _
    mCollection.Add objItemToAdd, Key
End Sub

Thanks in advance,

Linda

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

The views expressed in this e-mail are, unless otherwise stated, those of
the author and not of SDT or its management. The information is confidential
and is intended solely for the addressee.  All reasonable steps are taken
to ensure the accuracy, integrity and confidentiality of information.  No
liability or responsibility is accepted if information is corrupted or does
not reach its intended destination.  This e-mail message has been scanned
for viruses and cleared.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to