Listen for form events......

  • Thread starter Thread starter Alex Stevens
  • Start date Start date
A

Alex Stevens

Hi All,

I have a situation where I have two forms - FormA and FormB.

FormA has a list of Customers which when you double-click open the selected
customer.
FormB displays that Customer.
FormB has a public event called CustomerChanged(CustomerID as Int32) which
is raised with the current CustomerID when the form closes and the details
have changed.

What I want to do is have FormA know when the details in FormB have changed
so it can update the list details.
That is easy when you spawn one FormB and listen to it by declaring the
FormB as module level variable:

Public WithEvents frm as new FormB

and then Having a method PickupCustomerChanged which Handles
frm.CustomerChanged, pick up the CustomerID and updates the list entry:

Public Sub PickupCustomerChanged(CustomerID as Int32) Handles
frm.CustomerChanged

The question is how can I spawn more than one FormB??
The module level variable can only hold one form pointer/reference so the
PickupCustomerChanged method runs only when the last FormB that was opened
closes........

How can I monitor more than one form's events?

Thanks

Alex
 
Hi,

After some rooting around and trying the AddHandler I seem to have something
working.

By using this to open FormB:

Dim frm as new FormB
FormB.GetCustomer(123)
FormB.Show
AddHandler FormB.CustomerChanged, AddressOf PickUpCustomerChanged

this seems to tap into the event for that SPECIFIC INSTANCE of FormB.

So you could spawn as many FormB's as you like, and the AddHandler would
point the delegate for the Raised event to the method on FormA

Great.

Alex
 
Back
Top