2012-11-20 27 views
-1

我有一個包含網格的當前表單。我創建一個函數,當我雙擊這個網格的行時,打開一個新窗體。C#Winform關閉當前表單

public partial class Liste_Ordres : DevExpress.XtraEditors.XtraForm 
    { 
     public string Id = ""; 
     LeOrdre_BL oOrdre_BL = new LeOrdre_BL(); 
     LeOrdreStatut_Entite_BL oStatutOrdre_BL = new LeOrdreStatut_Entite_BL(); 

     public Liste_Ordres() 
     { 
      .... 
     } 

    private void Liste_DobleClic(object sender, EventArgs e) 
     { 
      try 
      { 
       Program.OrderId = gridView_Liste_Ordres.GetFocusedRowCellValue("NO_ORDRE").ToString(); 
       Program.StatusOrdre = Convert.ToInt32(gridView_Liste_Ordres.GetFocusedRowCellValue("STATUT_ORDRE")); 
       if (gridView_Liste_Ordres.GetFocusedRowCellValue("MODAL_MODE").ToString() == "A") 


       Fiche_Ordre f_Fiche = new   Fiche_Ordre(gridView_Liste_Ordres.GetFocusedRowCellValue("NO_ORDRE").ToString()); 
       f_Fiche.MdiParent = this.MdiParent; 
       f_Fiche.Show(); 
      } 
      catch (Exception excThrown) 
      { 
       MessageBox.Show(excThrown.Message); 
      } 
     } 

我該如何關閉Liste_Ordres? 當我把this.close();由於參考對象爲零,因此無法工作。

+0

當您嘗試使用this.Close()時會得到什麼確切錯誤? – mjcopple

回答

0

聲明您在Liste_DobleClic事件的類範圍外的表單對象f_Fiche以使其可用於該類的其他方法。

Fiche_Ordre f_Fiche = null; 

private void Liste_DobleClic(object sender, EventArgs e) 
{ 
     try 
     { 
      Program.OrderId = gridView_Liste_Ordres.GetFocusedRowCellValue("NO_ORDRE").ToString(); 
      Program.StatusOrdre = Convert.ToInt32(gridView_Liste_Ordres.GetFocusedRowCellValue("STATUT_ORDRE")); 
      if (gridView_Liste_Ordres.GetFocusedRowCellValue("MODAL_MODE").ToString() == "A") 


      f_Fiche = new   Fiche_Ordre(gridView_Liste_Ordres.GetFocusedRowCellValue("NO_ORDRE").ToString()); 
      f_Fiche.MdiParent = this.MdiParent; 
      f_Fiche.Show(); 
     } 
     catch (Exception excThrown) 
     { 
      MessageBox.Show(excThrown.Message); 
     } 
} 
+0

謝謝,但是我想關閉Liste_Ordres而不是Fiche_Ordre – user609511

+0

你可以使用this.Close(); – Adil

+0

我已經試過,但它不起作用 – user609511

相關問題