欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#最简单的关闭子窗体更新父窗体的实现方法

程序员文章站 2023-12-09 23:36:57
主窗体form1关键代码: 将子窗体最为对话框模式弹出,当窗体关闭或取消时更新主窗体 复制代码 代码如下: private void simplebutton1_click...
主窗体form1关键代码:

将子窗体最为对话框模式弹出,当窗体关闭或取消时更新主窗体
复制代码 代码如下:

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();
}
}

子窗体
复制代码 代码如下:

private void simplebutton1_click(object sender, eventargs e)
{
this.close();
}

public datatable createtable()
{
datatable tablea1 = new datatable();
tablea1.columns.addrange(new datacolumn[] { new datacolumn("名称"), new datacolumn("规格"), new datacolumn("单号"), new datacolumn("数量") });
tablea1.rows.add(new object[] { "螺旋", "ls-x", "111", "2" });
tablea1.rows.add(new object[] { "螺旋", "ls-x", "222", "1" });
tablea1.rows.add(new object[] { "指针", "lx-3", "523", "2" });
tablea1.rows.add(new object[] { "其他", "l-1", "666", "2" });
tablea1.rows.add(new object[] { "其他", "l-1", "456", "1" });
tablea1.rows.add(new object[] { "其他", "l-1", "990", "2" });
return tablea1;
}