C is the easiest way to close the child form and update the parent form

  • 2020-05-07 20:20:58
  • OfStack

Main form Form1 key code:

Pops the child form up in dialog mode and updates the main form when the form is closed or canceled
 
private void simpleButton1_Click(object sender, EventArgs e) 
{ 
Form2 f2 = new Form2(); 
f2.Owner = this; 
DialogResult result=f2.ShowDialog(); 
if (result == DialogResult.Cancel) 
{ 
this.gridControl1.DataSource = f2.CreateTable(); 
} 
} 

Child form
 
private void simpleButton1_Click(object sender, EventArgs e) 
{ 
this.Close(); 
} 

public DataTable CreateTable() 
{ 
DataTable tableA1 = new DataTable(); 
tableA1.Columns.AddRange(new DataColumn[] { new DataColumn(" The name of the "), new DataColumn(" specifications "), new DataColumn(" Order no. "), new DataColumn(" The number of ") }); 
tableA1.Rows.Add(new object[] { " spiral ", "LS-X", "111", "2" }); 
tableA1.Rows.Add(new object[] { " spiral ", "LS-X", "222", "1" }); 
tableA1.Rows.Add(new object[] { " Pointer to the ", "LX-3", "523", "2" }); 
tableA1.Rows.Add(new object[] { " other ", "L-1", "666", "2" }); 
tableA1.Rows.Add(new object[] { " other ", "L-1", "456", "1" }); 
tableA1.Rows.Add(new object[] { " other ", "L-1", "990", "2" }); 
return tableA1; 
} 

Related articles: