I have this button with the code:
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();
}
The FormClosedEventHandler looks like this:
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());
where the AddRow method adds rows to DataGridView. My problem is that when i close the sp form the rows are not added to the DataGridView.
FormClosedoccurs whenever the user closes the form, after the form has been closed and specifies the close reason.The reason for your code not working might be that some controls on the form are already destroyed…
I suggest you use
FormClosingevent which occurs whenever the user closes the form, before the form has been closed and specifies the close reason.Example code (it is very similar to what you did above):