2016-08-01 59 views
0

我有两种形式(frmMain和frmchild_list)。当我点击frmMain中的按钮时,frmchild_list将弹出,数据现在填充到datagridview中。如果单击frmchild_list中的数据行,我想将选定的datagridview的值传递给parent中的textbox。子datagridview父级文本框winform

这里我的代码在父

private void button2_Click(object sender, EventArgs e) 
{ 
    if(radioButton1.Checked) 
    { 
     f1.frmchild_list f = new f1.frmchild_list(this, "Y"); 
     f.MdiParent = this; 
     f.Show(); 
    } 
    else 
    { 
     f1.frmchild_listf = new f1.frmchild_list(this, "N"); 
     f.MdiParent = this; 
     f.Show(); 
    } 
} 

public static string itemx 
{ 
    set 
    { 
     txtItem.Text = value; 
    } 
} 

我的代码中的孩子:

Form m_parent; 
public frmIdH(Form f, string loc) 
{ 
    InitializeComponent(); 
    loaddata(loc); 
    m_parent = f; 
} 

public void loaddata(string location) 
{...} 

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) 
{ 
    m_parent.itemx = "sss"; 
} 

回答

0

经过几个小时的搜索到网络,我发现这篇文章,解决我的问题。 Link here

0

通过构造函数传递datagridview的数据。

或者

子窗体的父窗体创建一个实例。然后填充datagridview。 确保datagridview是公开的