views:

56

answers:

2

I have to catch an event from a parent dialog that uses a method from a static class to update an array.

From this dialog I call a child dialog that shows the array in a list.

I know with a variable if the current dialog is the child or the parent dialog, but from the method in the static class how can I call the method inside the child dialog to update the list when I catch the event?

+1  A: 

You could pass the instance of the dialog into the static method like below. I would definitely revisit your architecture if you're having a static method call into your dialog's methods however.

public static class MyStaticClass
{
   public static void SomeMethod(Form myDialog)
   {
      myDialog.SomeMethodOnTheDialog();
   }
}
Steve Danner
i'll try to set a catch event in every dialog that call a method inside for call the method in the class, so when it come back from the class method, i can use local method in dialog with no problem. But is possible to reset the catch for the parent dialog before open the child dialog? do i have to set it = null?
Leen15
A: 

You'll have to modify your static method to take an instance of the Dialog as a parameter:

public static void UpdateArray(Dialog instance)
{
     // Initialize what you need

     instance.DoSomething();
}

Then you would all it in your Event Handler like:

public void Dialog_EventHandler(object sender, EventArgs e)
{
    Dialog dialog = (Dialog) sender;
    UpdateArray(dialog);
}
Justin Niessner
Yes, but i think that if i set the catch in parent and child dialogs togheter, i don't have the right Dialog instance in the UpdateArray.. So the catch is for the first that i set, or random choose? i develope in netcf 3.5, the parent dialog is opened but hide, only the child dialog is shown..
Leen15