views:

19

answers:

1

I'm using http://sourceforge.net/projects/dockpanelsuite/ as a docking control in my application and I have added a form as a docking container, and from it I need to access a string from the main form. I was just messing around to see if I could load it using (Owner as MainWindow), but it did not work.

        for (int i = 0; i < (Owner as MainWindow).str.Count; i++)
        {
            MessageBox.Show("A");
        }

I always get an error on the first line "Object reference not set to an instance of an object." Is there any way I can access the string str (it is a public string btw) from the docked form?

If it's unclear please let me know.

A: 

Pass a ref of the MainForm when you create this form (your docking container). e.g.

add a constructor in your docking container:

MainForm GUImainform;
public dockingContainerForm(ref MainForm mymainform)
{
   GUImainform=mymainform;
}

so you can pass MainForm ref to this form when its created:

dockingContainerForm dcForm=new dockingContainerForm (ref this);

and access your MainForm inside this docking form with GUImainform.

Bolu
Huh? Could you explain what you mean by ref? I don't quite understand..
david
@David: updated.
Bolu
Cool, thanks for the info :)
david