Hi Guys -
This is my first C# app, but I have some knowledge of a bunch of languages like VB6 and PHP, so I'm picking it up rather quickly. I've been pulling my hair out on this one for about 4 hours now.
I have a DirectoryInfo on my parent form: (extra bits chopped out...)
And when I try to access it on my child form:
it throws a System.NullRefe renceException when opening the child form at run time.
I wish I would have kept better records of what all I've tried, but I got frustrated. I can tell you I've tried accessing the DirectoryInfo directly, and several variations of things like this
I'm sure it's something incredibly easy that I'm missing, any help would be appreciated.
This is my first C# app, but I have some knowledge of a bunch of languages like VB6 and PHP, so I'm picking it up rather quickly. I've been pulling my hair out on this one for about 4 hours now.
I have a DirectoryInfo on my parent form: (extra bits chopped out...)
Code:
public partial class frmMain : Form { public DirectoryInfo diTemp; private void frmMain_Load(object sender, EventArgs e) { diTemp = Directory.CreateDirectory("c:\\temp"); } private void btn1B_ExportCSV_Click(object sender, EventArgs e) { frm1B_ExportCSV f = new frm1B_ExportCSV(); f.ShowDialog(this); } public string setWorkingDir(string strSubdir) { diTemp.CreateSubdirectory(strSubdir); return diTemp.FullName + "\\" + strSubdir; } }
Code:
public partial class frm1B_ExportCSV : Form { private string strWorkingDir; private void frm1B_ExportCSV_Load(object sender, EventArgs e) { strWorkingDir = ((frmMain)this.ParentForm).setWorkingDir("1B"); } }
I wish I would have kept better records of what all I've tried, but I got frustrated. I can tell you I've tried accessing the DirectoryInfo directly, and several variations of things like this
Code:
//Cast MDIParent to your MDIParent Form theMDIParentForm theParent = (theMDIParentForm) this.MDIParent; //Now you can access objects on the MDI Parent form from MDI Children theParent.myTreeViewControl.Nodes[0].Add(new TreeNode("New Child Node"));
Comment