C#最簡(jiǎn)單的關(guān)閉子窗體更新父窗體的實(shí)現(xiàn)方法
更新時(shí)間:2012年11月29日 20:09:37 作者:
原理就是將子窗體最為對(duì)話框模式彈出,當(dāng)窗體關(guān)閉或取消時(shí)更新主窗體
主窗體Form1關(guān)鍵代碼:
將子窗體最為對(duì)話框模式彈出,當(dāng)窗體關(guān)閉或取消時(shí)更新主窗體
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("規(guī)格"), new DataColumn("單號(hào)"), new DataColumn("數(shù)量") });
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;
}
將子窗體最為對(duì)話框模式彈出,當(dāng)窗體關(guān)閉或取消時(shí)更新主窗體
復(fù)制代碼 代碼如下:
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();
}
}
子窗體
復(fù)制代碼 代碼如下:
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("規(guī)格"), new DataColumn("單號(hào)"), new DataColumn("數(shù)量") });
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;
}
相關(guān)文章
C# 如何使用 Index 和 Range 簡(jiǎn)化集合操作
這篇文章主要介紹了C# 如何使用 Index 和 Range 簡(jiǎn)化集合操作,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-02-02WinForm項(xiàng)目開(kāi)發(fā)中Excel用法實(shí)例解析
這篇文章主要介紹了WinForm項(xiàng)目開(kāi)發(fā)中Excel用法,非常實(shí)用,需要的朋友可以參考下2014-08-08ScriptControl控件執(zhí)行自定義VBS腳本示例分析
這篇文章主要介紹ScriptControl控件 msscript.ocx msscript.oca執(zhí)行自定義VBS腳本的示例代碼,需要的朋友可以參考下2013-04-04C#(.net)中按字節(jié)數(shù)截取字符串最后出現(xiàn)亂碼問(wèn)題的解決
這篇文章主要給大家介紹了關(guān)于C#(.net)中按字節(jié)數(shù)截取字符串最后出現(xiàn)亂碼問(wèn)題的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06C#RSA對(duì)接JAVA中RSA方式代碼實(shí)例
在本篇文章中小編給各位整理的是關(guān)于C#RSA對(duì)接JAVA中RSA方式代碼實(shí)例,有需要的朋友們可以參考一下。2019-09-09C# 使用鼠標(biāo)點(diǎn)擊對(duì)Chart控件實(shí)現(xiàn)數(shù)據(jù)提示效果
這篇文章主要介紹了C# 使用鼠標(biāo)點(diǎn)擊對(duì)Chart控件實(shí)現(xiàn)數(shù)據(jù)提示效果,文章給予上一篇的詳細(xì)內(nèi)容做延伸介紹,需要的小伙伴可任意參考一下2022-08-08