Pregunta

Can someone provide me with an example please?

Scenario is:

 **FORM1** = MDIPARENT
FORM2 = CHILD
FORM3 = CHILD

FORM2 is opened by a menu on MDIPARENT FORM2 has a text box - CompanyNameText next to this textbox there is a button which opens FORM3 containing a list

What I m trying to achieve is for the user to select a company name from the list in FORM3 and their selection to show up in FORM2's Companynametextbox

I've tried :-

FORM3:-  

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim formChild2 As AllocateCallBack = DirectCast(Me.MdiParent.MdiChildren(1), AllocateCallBack)
    formChild2.ReceiveValue(SelectTextBox.Text)
    End Sub

FORM2:-

Public Sub ReceiveValue(ByVal value As String)
    CompanyNameTextBox.Text = value.ToString
    Me.Activate()
    Me.Refresh()
    End Sub

But I am getting message Nullreferenceexception` was unhandled.

I've confirmed that the SelectTextBox has a value prior.

Help please

¿Fue útil?

Solución

You can add this code to the button in FORM2 which open FORM3.

Dim frm3 As New FORM3()

If frm3.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
    Me.DoWhatYouWantWithThisValue(frm3.SelectTextBox.Text)
End If

When the user select a company from the list in FORM3 you must set:

Me.DialogResult = Windows.Forms.DialogResult.OK
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top