C#中怎样把一个窗体中的text和combobox还有一个datatimepicker填到另一个窗体的datagridview中?

来源:百度知道 编辑:UC知道 时间:2024/06/15 05:38:01
点第一个窗体的添加按扭就到第二个窗体的datagridview中了.
求教各位大虾们!!!!
我不胜感激!

楼主把它们都改成用户控件岂不更方便?

在第二个窗体里写个函数
public addrow(string a,string b,string c)
{
this.datagridview1.rows.add(.....)
//把数据填入
}

然后在第一个窗体里
Form2 f2=new Form2();
f2.show();
f2.addrow(this.textbox1.text,........)

用一楼的方法实验下,比如说你datagridview中有字段a, b, c三个字段,那么就是这样,
DataRow dr = new DataRow();
dr["a"]=this.textbox.text;
dr["b"]=this.combox.se....text;
dr["c"]=....值
this.datagridview.rows.add(dr);
好像是这样的,你测试下看看不行再说了,
一楼的代码是精辟

在第一个窗体form1按钮的点击事件里面写 (窗体命名form1 form2)
string text = this.TextBox1.text.ToString();
string cb = this.combobox1.text.tostring();
form1 f1 = new form1(text,cb);
f1.show();
在第二个窗体的构造方法里面接收传过来的值(自己先定义 然后把传过来的值接收一下)
在load时间里面 把接收好的值给gv就可以了