John Nuñez
John Nuñez

Reputation: 1830

Manipulating Controls On Parent Forms From Child VB.NET

I'm trying to add a new row to a DataGridView from FORM 2 but I can not succeed, the code I tried is as follows:

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

Looking like it took time but can not find a solution, someone who can help me with my problem would be nice, Thank You.

Upvotes: 2

Views: 820

Answers (1)

Prince Jea
Prince Jea

Reputation: 5680

Try this This work only if you use a showdialog.

Form 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

Form 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

Upvotes: 3

Related Questions