有窗体form1和窗体form2,现在如何form2中的值传给form1的变量。求高手!!急!!

zihaobiao 2012-04-03 09:50:44
有窗体form1和窗体form2,现在如何将form1的datatable做为数据源绑定到form2中的DataGridView中。并且当双击form2中的DataGridView中的某一行时将DataGridView中这一行中的第一列的值付给form1中的strNewcode变量,同时form1关闭。这个怎么实现?求详解!!这是我自己写的代码,但不能实现,求大虾们指点下。form1中的部分代码form2selectbill = new form2();
selectbill.dgvBillInfor.DataSource = dtNew;
selectbill.Visible = false;
string strNewcode = "";
selectbill.Returnvalue = new SelectBill.retunvalue(Showvalue);
selectbill.ShowDialog();form2中的部分代码 public delegate void retunvalue(string strBillcode);
public retunvalue Returnvalue;


private void dgvBillInfor_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0) return;
DataGridViewRow dgvrBill = dgvBillInfor.CurrentRow;
if (dgvrBill != null)
{
string strBillCode = dgvrBill.Cells["Cwcwewbcode"].Value.ToString();
if (string.IsNullOrEmpty(strBillCode)) return;
Returnvalue(strBillCode);
}
}
...全文
109 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
orochiheart 2012-04-03
  • 打赏
  • 举报
回复
Form1中
Form2 fm2 = new Form2(this);


Form2构造函数
Form2 fm = new Form2();
public Form1(Form _fm)//构造函数
{
InitializeComponent();
fm = _fm;
}
private void button1_Click(object sender, EventArgs e)
{
fm.我的控件
}
SaintLance 2012-04-03
  • 打赏
  • 举报
回复
感觉问题不大,要不你吧那个ReturnValue的代理直接做成事件试试?
yuandonghuia 2012-04-03
  • 打赏
  • 举报
回复
把要传的值,直接设置成public属性,然后在form2中把直接取。不过form2中要有form1这个字段。如果不懂,先看看面向对象,类的概念,从面相过程的想法过来,这里会非常别扭。

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧