Setting MdiParent from child form

user609511 picture user609511 · Nov 14, 2012 · Viewed 16.5k times · Source

I have a principal form that contains a menu to open child form:

public Le_MainForm()
{ 
  InitializeComponent();
  this.IsMdiContainer = true;
  .....
}

private void barButtonItem_CreatOrdreAller_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
  Close_AllForm();
  Program.StatusOrdre = 1;
  Program.AllerRetour = "Ordre Aller";
  Fiche_Ordre f_Fiche = new Fiche_Ordre();
  f_Fiche.MdiParent = this;
  f_Fiche.Show();
}

It works well, but I open another form from child, I lost MdiParent:

public Liste_Ordres()
{
  InitializeComponent();
  ....
}

private void Liste_DobleClic(object sender, EventArgs e)
{
  Fiche_Ordre f_Fiche = new Fiche_Ordre(gridView_Liste_Ordres.GetFocusedRowCellValue("NO_ORDRE").ToString());
  f_Fiche.ShowDialog();
}

Answer

LarsTech picture LarsTech · Nov 14, 2012

Try setting the form like this:

Fiche_Ordre f_Fiche = new Fiche_Ordre(gridView_Liste_Ordres.GetFocusedRowCellValue("NO_ORDRE").ToString());
f_Fiche.MdiParent = this.MdiParent;
f_Fiche.Show();

ShowDialog() is for a pop-up modal form.