C#最簡單的關(guān)閉子窗體更新父窗體的實現(xiàn)方法
更新時間:2012年11月29日 20:09:37 作者:
原理就是將子窗體最為對話框模式彈出,當窗體關(guān)閉或取消時更新主窗體
主窗體Form1關(guān)鍵代碼:
將子窗體最為對話框模式彈出,當窗體關(guān)閉或取消時更新主窗體
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("單號"), 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)閉或取消時更新主窗體
復(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("單號"), 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)文章
vs2019 實現(xiàn)C#調(diào)用c++的dll兩種方法
這篇文章主要介紹了vs2019 實現(xiàn)C#調(diào)用c++的dll兩種方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
C#使用Datatable導(dǎo)入sqlserver數(shù)據(jù)庫的三種方法
本文主要介紹了C#使用Datatable導(dǎo)入sqlserver數(shù)據(jù)庫的三種方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-08-08
C#使用IronPython庫調(diào)用Python腳本
這篇文章介紹了C#使用IronPython庫調(diào)用Python腳本的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06
Unity實現(xiàn)攻擊范圍檢測并繪制檢測區(qū)域
這篇文章主要介紹了Unity實現(xiàn)攻擊范圍檢測并繪制檢測區(qū)域,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-04-04
深入理解c# checked unchecked 關(guān)鍵字
本篇文章是對c#中的checked unchecked 關(guān)鍵字進行了詳細的分析介紹,需要的朋友參考下2013-05-05

