Something like this will work:
Public Delegate Sub AnEventHandler( ByVal sender As Object, ByVal e As
EventArgs)
Public Class Job
Public CandidateCollec tion As New Collection
Public Sub AddCandidate(By Val aCandidate As Candidate)
CandidateCollec tion.Add(aCandi date)
End Sub
Public Sub AProcedure(ByVa l sender As Object, ByVal e As EventArgs)
' code here
Console.WriteLi ne("Test")
End Sub
End Class
Public Class Candidate
Public Event AnEvent As EventHandler
Private mName As String
Public Property Name() As String
Get
Return mName
End Get
Set(ByVal Value As String)
mName = Value
' now trigger Job AProcedure
Dim e As New EventArgs
OnAnEvent(e)
End Set
End Property
Protected Overridable Sub OnAnEvent(ByVal e As EventArgs)
RaiseEvent AnEvent(Me, e)
End Sub
End Class
Dim jb As New Job
Dim cand As New Candidate
AddHandler cand.AnEvent, AddressOf jb.AProcedure
jb.AddCandidate (cand)
jb.CandidateCol lection(1).Name = "Smith"
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities -
http://community.integratedsolutions.dk
"alanb" <ab**********@g mail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I have one object which holds a collection of other objects. I'll make
one up as my specific example is too abstract and too much code:
Public Class Job
Dim CandidateCollec tion As New Collection
Public Sub AddCandidate(By Val aCandidate As Candidate)
CandidateCollec tion .Add(aCandidate )
End Sub
Public Sub AProcedure()
' code here
End Sub
End Class
Public Class Candidate
Public Property Name() As String
Get
Return mName
End Get
Set(ByVal Value As String)
mName = Value
' now trigger Job AProcedure
End Set
End Property
End Class
What I'm trying to do is trigger an event in the Set Property Name to
run the sub in the class Job, i.e. when I run code:
Job.Candidate(1 ).Name = "Smith"
the sub AProcedure in Job runs. I suspect the answer may be a
reconstruction of the classes and/or collection, or is this legitimate
code with an easy way to call the sub?
TIA,
Alan