在form1里有一个按钮和一个datagridview,我把datagridview绑定到数据库里的T1表。现在我想点form1的按钮的时候弹出一个窗口form2,form2有很多textbox接受用户输入的数据,然后把这些数据作为T1的一条记录,返回到数据库的T1里,并且在form1里datagridview里显示新增出来这一条记录。该怎么办?
如果把form2里的textbox不放到form2中,放到form1中,就很容易实现,上述功能,因为他们在同一个窗口中。现在出现两个窗口怎么传递数据呢?
如果把form2里的textbox不放到form2中,放到form1中,就很容易实现,上述功能,因为他们在同一个窗口中。现在出现两个窗口怎么传递数据呢?
解决方案 »
- 如何解决datagridview绑定表时,空记录报异常IndxOutofRangeException
- 怎样重载运算符?
- C#中 如何读取TXT文件第N行内容
- 请教大家.Net C/S架构,如何从本地上传文件到文件服务器
- 求教 关于webservice
- 用C#.net制作不规则窗体到讨论(源码)
- 如何让DataGridView的一列如( DataGridViewTextBoxColumn列)全部处于编辑状态
- 细节上的难题(TXT)
- 请介绍一些有大量C#和asp.net源代码下载的网站
- 创建C# addin,如何在addin中生成FORM文件,并加上控件?
- 新手,想知道泛型以及泛型约束是什么意思
- 如何用comboBox在里面显示日期(如年,月,日,小时)
public Delegate void Reload(string content);
public class A:form 主窗体
{
...........
B b=new B();
b.ReloadEvent+=(sender)=>{this.textbox1.text=sender as string;};
} public class B:form 弹出窗体
{
public event Reload ReloadEvent;
..................
button.click +=(sender,args)=>
{
if(ReloadEvent!=null)
ReloadEvent(textbox2.text.trim());// 这里就代表该事件执行了。
};
}第二个,构造函数;
public class A:form 主窗体
{
private string content;
B b=new B(content);
if(b.showdilog()==dilogresult.ok)
{
this.textbox1.text=b.Content;
}
} public class B:form 弹出窗体
{
private string content;
public string Content(get return content;)
public B(string _content)
{content=_content;}
..................
btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
B.FormClosing +=(sender,args)=>
{
if (DialogResult == DialogResult.OK)
content=textbox2.text.trim();};
}