Andrew

Andrew

  • NA
  • 17
  • 0

MDI Child form interacting with its MDI Parents Controls - how?

Nov 23 2008 3:17 PM
Situation:

I have a MDI Parent which has a Treeview of data loaded at form_load event.

Clicking certain nodes of this Treeview opens a child form named 'Companies'. In Companies I display a datagrid. Double clicking on rows should change the Treenode that is selected in my MDI Parent (the childs parent).

However, I am getting a System.StackOverflowException when I double click on a DataGridRow.

Here is the Event handler

[code]
private void dgCompanies_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
   selectedCompany = dgCompanies.SelectedCells[0].Value.ToString().Trim();
   frmMain newFrmMain = (frmMain)this.MdiParent;
   newFrmMain.JumpToCompany(selectedCompany);
}
[/code]

And here is JumpToCompany which is a public event in frmMain

[code]
public void JumpToCompany(string companyName)
{
   try
   {
   foreach (TreeNode treeNode in this.trvCompanyVesselList.Nodes)
   {
      if (treeNode.Tag.ToString() == companyName)
      {
         trvCompanyVesselList.SelectedNode = treeNode;
         trvCompanyVesselList.Focus();
         foundIndex = true;
      }
      JumpToCompany(companyName);
      }
   }
   catch (StackOverflowException se)
   {
      MessageBox.Show(se.Message);
   }
}
[/code]

So, in a nutshell, can I interact with controls on a MDI Parent form, which is triggered by an event on a Child form?

Cheers