473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Raising Events From Objects In A Collection

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

Nov 20 '05 #1
3 2003
In article <#D**************@TK2MSFTNGP10.phx.gbl>, Franky wrote:
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.
--
Tom Shelton [MVP]
Nov 20 '05 #2
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
"Franky" <fr***************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 20 '05 #3
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=cls...fp-t-417&x=wrt

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Sep 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bob | last post by:
Is there an interface or events in the system that occurs pre and post garbage collection that one of my objects can attach to? I need to know in my application when garbage collection is about to...
2
by: Krzysztof Malinowski | last post by:
Hi, We can raise an event by calling some method the same like a delegate. Actually one event can reference a few different method each of these meets delegate declaration. Like below: (...)...
2
by: Jon Davis | last post by:
The garbage handler in the .NET framework is handy. When objects fall out of scope, they are automatically destroyed, and the programmer doesn't have to worry about deallocating the memory space...
15
by: Rhy Mednick | last post by:
I have a class (let's call it ClassA) that I've written which has events. In another class (let's call it ClassB) I create a collection of ClassA objects. In a third class (ClassC) I create a...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
7
by: cider123 | last post by:
I'm coding a project using the following article as reference: http://www.codeproject.com/csharp/DynamicPluginManager.asp In this type of project, plugins are loaded dynamically into a Plugin...
4
by: Dave A | last post by:
I am developing a somewhat complex component at the moment and coincidently I am also reading the Framework Design Guidelines book. After reading the section about event raising I have re-written...
1
by: Asko Telinen | last post by:
Hi all. I ran into quite strange problem concerning the event raising inside FileSystemWatcher Delete event. First, i would like to describe a bit my environment. I have main GUI...
7
by: nick.fletcher | last post by:
I have a custom collection which derives from Collection<which stores a number of objects. Before each item is added to the collection - an event which it exposes is hooked by the collection and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.