2012-01-31 13 views
0

でFormClosedイベントをハンドル:FormClosedEventHandlerはこのようになります私はコードでは、このボタンを持ってリサイズ

private void button22_Click_1(object sender, EventArgs e) 
    { 
     Separare sp = new Separare(dataGridView1,label_pin.Tag.ToString(),label_pin.Text); 
     sp.FormClosed += new FormClosedEventHandler(ClosedForm); 
     sp.Show(); 

    } 

AddRowメソッドは、DataGridViewのに行を追加します
DataTable bon_temp = bon_tempTableAdapter.GetDataByTable(label_pin.Tag.ToString()); 

     foreach (DataRow row in bon_temp.Rows) 
     { 
      AddRow(row.ItemArray[3].ToString(), Convert.ToInt32(row.ItemArray[4]), Convert.ToDecimal(row.ItemArray[5])); 
      Console.WriteLine(row.ItemArray[3].ToString(), Convert.ToInt32(row.ItemArray[4]), Convert.ToDecimal(row.ItemArray[5])); 
     } 

     bon_tempTableAdapter.DeleteQuery(label_pin.Tag.ToString()); 

。私の問題は、私がspフォームを閉じると、行がDataGridViewに追加されないということです。ユーザーがフォームを閉じられた後、フォーム、を閉じ、クローズ理由を指定するたび

+0

? –

+0

おそらく、Debug.WriteLineを使用する代わりに、WinForms AppではConsole.WriteLineがVSコンソールに書き込みを行うためです。 –

+0

AddRowはどこに定義されていますか? –

答えて

6

FormClosedが発生します。私は、ユーザーがフォームを閉じたときに発生するFormClosingイベントを使用することをお勧め

あなたのコードのために働いていない理由は、フォーム上のいくつかのコントロールが既に破壊されるかもしれない...

前にフォームがあり閉鎖され、近い理由が明記されている。

例コード(それはあなたが上記のやったことに非常に似ている):なぜあなたはWinFormsのアプリケーションにコンソールに書いている

this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MyMainForm_FormClosing); 

... 

private void MyMainForm_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    //your code goes here 
    //optionally, you can get or set e.Cancel which gets or sets a value indicating that the event should be cancelled; in this case the form won't close if you cancel it here 
    //or, you can check e.CloseReason which gets a value that indicates why the form is being closed (this is an enum Systems.Windows.Forms.CloseReason) 
} 
+0

FormClosingの標準的な例を教えてください。 –

+0

@Emil:似たような例ですが、似たようなものです。 :) Succes。 – woohoo

関連する問題