CollectionBase.OnSetComplete Method?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shannon Richards

    CollectionBase.OnSetComplete Method?

    Hello All: Can anyone tell what exactly this method is supposed to be used
    for? I have a class that derives from CollectionBase. This class overrides
    the OnSetComplete() method to raise an event when a child object changes?

    example: The overridden OnSetComplete() method in the collection class

    Protected Overrides Sub OnSetComplete(B yVal index As Integer, ByVal oldValue
    As Object, ByVal newValue As Object)
    RaiseEvent Changed ()
    End Sub

    -----------------------------------------------------------------------------------------

    example: Class contained int he collection tells the collection that it's
    been modified...

    Public Property Name() As String
    Get
    Return ms_Name
    End Get
    Set(ByVal Value As String)
    ms_Name = Value
    If (Not mo_Parent Is Nothing) Then
    Dim li_Idx As Integer = mo_Parent.Index Of(Me)
    mo_Parent(li_Id x) = Me
    End If
    End Set
    End Property


    The problem is when I loop through the collection of these objects changing
    properties etc I get an error:

    An unhandled exception of type 'System.Invalid OperationExcept ion' occurred
    in mscorlib.dll
    Additional information: Collection was modified; enumeration operation may
    not execute.


    Can anyone explain this to me? I believe it's because mo_Parent(li_Id x) =
    Me
    actually sets the current enumerator position in the collection class and
    you cannot do that inside a loop?

    Thanx,
    Shannon Richards
    BBA, AIT, MCP



Working...