Raising Events From Objects In A Collection

F

Franky

IN vb.Net

Class clsCommande Inherits CollectionBase

and

Class clsProduct

clsCommand contain a IList of clsProduct


the clsProduct.Quantity property Raise an Event : Events ProductModify().

- How can I trap this event in clsCommande ?

__________________________________
Franky
Franky_NOSPAM_@Boucher_NOSPAM_os.com
 
T

Tom Shelton

IN vb.Net

Class clsCommande Inherits CollectionBase

and

Class clsProduct

clsCommand contain a IList of clsProduct


the clsProduct.Quantity property Raise an Event : Events ProductModify().

- How can I trap this event in clsCommande ?

__________________________________
Franky
Franky_NOSPAM_@Boucher_NOSPAM_os.com

If I'm understanding you correctly, you have a strongly typed collection
of a class that raises an event that you want the collection to catch...
If that's the case, then you'll want to just dynamically add and remove
the event handlers as the objects are added and removed from your
colleciton...

Public Function Add (ByVal value As clsProduct) As Integer
AddHandler value.ProductModify, AddressOf Me.EventHandlerMethod
Return Me.List.Add(value)
End Function

' you'll of course want to make this match what ever your signature is,
' but you might at least want to make sure the object parameter is there
' so you can tell which object raised the event
Private Sub EventHandlerMethod (ByVal sender As clsProduct, ByVal e As
EventArgs)

End Sub

Public Sub Remove (ByVal value As clsProduct)
RemoveHandler value.ProductModify, AddressOf Me.EventHandlerMethod
Me.List.Remove(value)
End Sub


Anyway, that is a basic off the cuff sketch to get you going.
 
C

Cablewizard

I think that Tom Shelton's suggestion would probably work.
But you might want to further define the relationship of the clsProduct to the
Collection.
Will clsProduct always belong to this type of Collection, or could it exist
outside the collection?
Could it exist in a different collection?
Do other objects besides the collection need to respond to Events from
clsProduct?
Basically, I'm trying to determine if a common Parent/Child relationship exists.
If that is the case, IMHO Events would be an inefficient way to go.
Hooking / Unhooking Events can be time consuming, you have no guarantee of when
the Event will be processed and/or which order, etc.
If a true Parent/Child relationship exists, then I would add a Parent property
to the clsProduct and assign it to the Collection when Adding. And of course
unassigning if removing.
Then when the Child is modified, it could just directly call an appropriate
method on the Parent.
This can be easily achieved using strongly typed parameters, or with Interface
Implementation.

Say a Child is modified, it could call the ChildModified Sub on it's parent.

clsProduct.Quantity changes, then in the Quantity property it could call
me.Parent.ChildModified(me)

I know that explanation was a little dis-jointed, but hopefully it made sense.

Gerald
 
M

Mike Wilson

Hi,

I figured out by searching through the Registry the command to start a database: "c:\Program Files\Sybase\SQL Anywhere 9\win32\dbsrv9.exe -hvASANYs_gwsrv". I am using Seagate Backup Exec 7.2 (1998) on a Windows NT server. There is an option to run a command script BEFORE and AFTER the backup. I need to know the command script to STOP the database so that the database can be included in the backup. THANKS!

From http://search.yahoo.com/search?p=clsCommand&ei=UTF-8&fr=yfp-t-417&x=wr

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top