form and delegates

  • Thread starter Thread starter Pohihihi
  • Start date Start date
P

Pohihihi

I have form A, B, and C

For C can be called from A or B but when ever something happence in C few
things on form A needs to be updated.

First way was register callback on A for B and then register call back on B
for C. That is a nested way of event but what I am looking is that if some
kind of event manager is in the main thread that is taking care of this. It
should also take care of unregistring the events for the closed forms (in
this case C).

How to do this? any pointers will help

Thank you,

Po
 
Hi,

I think it will be simpler if you just keep a reference to A in C. You said
that C can be called from A or B, but you did not especified if A is your
main form (always exist). If this is the case yuo could export a static
property with a reference to form A :
public class A:Form
{
static currentForm;
public static A { get{return currentForm;}

private form_load(.....)
{
currentForm = this;
}
}

then you can always get the main form using A.CurrentForm;


If not you could keep a reference to A in B, then when you create C from B
you pass it. If C is created from A you have the reference directly.

IMO this is simpler that using delegates,etc.

cheers,
 
Another possible option, besides the one Igacio gave you is to put the data
into a DataTable (even if it's only one row) and then bind the controls to
the DataTable. When you make updates to data in the DataTable, the controls
in any other forms will automatically get updated via the CurrencyManager.
It basically relieves you having to manage the stuff yourself.

Pete
 
Back
Top