form1中为某张数据表中的数据,有一个添加按钮,点击后打开form2输入新的一条数据,在form2中点击保存按钮保存后如何能刷新form1中的datagridview,使其显示出新添加的那条数据?
解决方案 »
- 求助关于W7图标的问题
- 有谁知道怎样让richtextbox显示动态图片?
- 高分救急:同一窗体的多个实例注册同一事件
- 为什么数据更新不到数据库中呢?
- 如何把一个string类型转换为byte[]????
- 如何获取窗口上所有的菜单项!
- if(!returnValue) 和if(false == returnValue)有什么区别
- 求一个正则表达式
- Inside C# 2nd---English Version,Who wants?
- C# Webbrowser加载嵌入资源的html,那html中的图片怎么引用?
- C# TCP/IP协议 如何解决Socket一次接收多个数据包的问题????
- 跪求windows平台下trac的AccountManager插件
保存后 重新绑定另一个窗体的datagridview
要刷新的窗体Form1using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ }
public void renovate()
{
//刷新的代码
}
}
}Form2的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
private Form1 _MyForm1 = new Form1(); public Form1 MyForm1
{
get { return _MyForm1; }
set { _MyForm1 = value; }
}
public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//回调Form1的刷新事件
_MyForm1.Invoke(new Action(_MyForm1.renovate));
//更多的操作可以看看Invoke的详细资料,也可以看看多线程之间的通信资料
}
}
}
{
frmEditLesson myAddLesson = new frmEditLesson();
// myAddLesson.Parent = this;
myAddLesson.ShowDialog();
if (myAddLesson.DialogResult == DialogResult.OK)
{
//查询窗体点了确认按钮,进行你要处理的代码,根据strwhere记录的条件进进行数据筛选然后绑定dataGridView就可以了
this.vSrayLessonTableAdapter.Fill(this.vSrayLessonDataSet.vSrayLesson);
} }以上是添加按钮代码,form2的保存按钮保存成功后加入一条语句:
this.DialogResult = DialogResult.OK;