How to raise event in a List Item class and cause an event in the custom List class

M

moondaddy

I wrote my own List class which I use to bind to list controls. this class
inherits CollectionBase and implements IBindingList. This class contains a
list of business classes such as customers for example. In the customer
class I have an event called MyTestEvent and when certain conditions arise,
I want to raise this event which would cause an event to fire in the List
class. How can this be done when I don't actually declare the customer
class in the List class like this:
Private WithEvents Cust as Customer

Customers are created and added to the List class like this

Dim obj As New Customer
obj.LoadDataRow(dr, ds.tbCustomer)
list.Add(obj)

In short, how do I wire up events from each Customer in the list object?

Thanks.
 
G

Guest

In your class use:
* Declare an Event (declare it as global - not in a function):
Public Event MyTestEvent()

* Use this command to activate this event in the class:
RaiseEvent MyTestEvent()

In the main form:
Private WithEvents Cust as Customer

In one of the functions:
\\\\\
Cust = New Customer
Cust.LoadDataRow(dr, ds.tbCustomer)
/////

Use this function to capture this event:
\\\\\
Private Sub foo() Handles Cust.MyTestEvent
...
End Sub
/////
 
M

moondaddy

Thanks but I dont see how this can work. Let me clarify the structure of
the objects:

Form1 has a grid control and makes a private reference to a custom class
that acts as a bindable collection (oList):
Private oList as New MyCustomCollectionClass

In MyCustomCollectionClass I use:
Inherits CollectionBase
Implements IBindingList


This class constains and manages a collection of business classes. I add
the bussiness classes like this:

dim obj as New MyBizClass
obj.Name=FooBar

list.Add(obj)

and list is from this:

Protected ReadOnly Property List() As System.Collections.IList
Member of: System.Collections.CollectionBase

OK. Now I have a colleciton of buisnes classes and in one of these business
classes I want to raise an event like you mentioned below:
'from a method one of the items in list
RaiseEvent MyTestEvent()

However, MyCustomCollectionClass has no formal reference to any of the
busienss classes so I can't use a line like this:

Private WithEvents Cust as Customer

All the business classes live completely in 'list'.

This is my delema.

Any further advise?

Thanks.
 
G

Guest

I have two forms.

I would like to click on a button in form1 and raise a event in form2. How
do accomplish this?
 

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