//實例化學(xué)生明細(xì)的窗體
public static frmStudentDetail frmsd;
//主窗體雙擊單元格的事件
private void dgvStudent_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)//雙擊單元格的事件
{
//通過Serverice類中的方法得到學(xué)生類
Student objectStudent = StudentService.GetStudentInfo(Convert.ToInt32( dgvStudent.CurrentRow.Cells[0].Value));
//更改識別操作的全局變量
actionFlag = 1;
//防止關(guān)閉明細(xì)窗體,再次打開是無響應(yīng),需要在明細(xì)窗體中將實例化的窗體置為空
if (frmsd == null)//判斷窗體是否已經(jīng)打開
{
//將實例化的窗體直接在次級窗體里面創(chuàng)建有參數(shù)的方法,直接將參數(shù)在打開時直接被調(diào)用
frmsd = new frmStudentDetail(objectStudent, actionFlag);//實例化Student窗體,并將數(shù)據(jù)傳遞到次級窗體
frmsd.Show();//顯示
}
else
{
frmsd.Activate();
frmsd.WindowState = FormWindowState.Normal;
}
}
//第二個窗體的事件(明細(xì)窗體)
public frmStudentDetail(Student objStudent/增加判斷增刪改的操作/,int actionFlag) :this()//在主窗體觸發(fā)這個窗體的有參數(shù)的方法之前首先運行窗體默認(rèn)的無參的方法。并接受傳遞的參數(shù)
{文章來源地址http://www.zghlxwxcb.cn/news/detail-441669.html
}
private void frmStudentDetail_FormClosing(object sender, FormClosingEventArgs e)//窗體關(guān)閉的事件
{ //防止關(guān)閉明細(xì)窗體,再次打開是無響應(yīng),需要在明細(xì)窗體中將實例化的窗體置為空
frmMain.frmsd = null;//frmsd為主窗體中實例化第二個窗體
}
文章來源:http://www.zghlxwxcb.cn/news/detail-441669.html
到了這里,關(guān)于雙擊dataGridView控件中的數(shù)據(jù)行,彈出另一個窗體,并將數(shù)據(jù)傳遞到另一個窗體中的方法。實現(xiàn)窗體調(diào)用,并數(shù)據(jù)傳輸?shù)奈恼戮徒榻B完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!