2012-03-06 66 views
2

我想一個新行從表格2添加到一個DataGridView,但我能不能成功,我試過代碼如下:操作控件在父窗體從子VB.NET

FORM 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 

看起來需要時間但找不到解決方案,有人可以幫我解決我的問題,謝謝。

+0

這是形式2顯示對話框的形式? – 2012-03-06 15:59:52

回答

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 
+0

你的答案幫助我很多謝謝:) + Rep – 2012-03-06 17:40:11

相關問題