Hi
I am toying with an APP and I open an XMLDocument in the main form.
I am trying to access the already opened XML document from a userControl... However I tried using a getter/setter (loadedXDoc) in Form1 then using Form1 f1 = new Form1(); in the userControl.
Then tried f1.loadedXDoc and when it enters the getter setter the values are null? Yet when i step into this get/set method during load of the document i see these values set correctly...
I believe this to be down to the new Form1 method but am quite stuck on this any assistance welcome.
Hope i explained well enough.

1 answers
The problem is that when you execute this line from the UserControl:
it creates a new instance of Form1 rather than obtaining a reference to the existing instance.
If the UserControl is on Form1, then this code should do what you want:
However, if you want to use the UserControl on a different form you'll need to remember to remove or modify this code, otherwise it won't compile.
answered 6 months ago by:
12813
152
Hi Vulpes have not tried this but managed to keep on trying and the following also seems to work... Which would you say was the better approach the above or this: [code] class xBaseLoaded { private static string baseFile; public string thisBase { get { return baseFile; } set { baseFile = value; } } } [/code]
12813
That approach might be better as it removes the dependency between the main form and the XmlDocument. However, you'll still need access to the xBaseLoaded class if the UserControl is deployed elsewhere.