从子VB.NET操作父窗体上的控件

时间:2012-03-06 15:46:15

标签: vb.net forms controls

我正在尝试从FORM 2向DataGridView添加一个新行,但我无法成功,我尝试的代码如下:

表格2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FORM1.invoice_items.Rows.Add()
    End Sub

看起来需要时间但找不到解决方案,有人可以帮助我处理我的问题会很好,谢谢。

1 个答案:

答案 0 :(得分:3)

试试这个 仅当您使用showdialog时才能使用。

表格2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       'Pass the value to be added in the datagrid to form 1
       Me.DialogResult=Windows.Forms.DialogResult.OK

End Sub

表格1:

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      If Form2.ShowDialog = Windows.Forms.DialogResult.OK Then
    'Getthe value from form 2
    invoice_items.Rows.Add()
    End If
End Sub