近几天写小系统遇到的问题。查了很久网站,最后是自己踩着石头过河……
解决方案如下:
1,父窗口中的DataGridview属性设为public;
再添加
public frmForm MotherForm;
2,在父窗口的打开子窗体事件中
private void btnNewForm(object sender, EventArgs e)
{
frmNewForm fnf = new frmNewFrom();
fnf.MotherForm = this;
fnf.ShowDialog();
}
3,在子窗口中
private void btnEvent(object sender, EventArgs e)
{
............................
MotherForm.DataGridView.DataSource = null;
MotherForm.DataGridView.DataSource = //绑定数据源
............................
ok...
}
大概解决流程就这样了,可能还有不足的地方。
本文介绍了一种在子窗体中更新父窗体DataGridView的方法,通过将DataGridView属性设置为public,并传递父窗体实例到子窗体,实现在子窗体中更新DataGridView的数据源。

406

被折叠的 条评论
为什么被折叠?



