Domanda

I am trying to return some data from a subform I open with showdialog

I referred to this question on stack overflow: VB.NET Pass Data Between Forms

Here is the code. I know the code you write on the subform:

Public Property CustomerID as Integer

Private Sub OK_Click(s as Object, e as eventargs) Handles OK.Click
    CustomerID = id 'pass the value here
    Me.DialogResult = DialogResult.Ok
End Sub

But I dont know where to enter the code that goes in the main form

If frmChild.ShowDialog = DialogResult.Ok Then
    MessageBox.Show("Customer ID: " + frmChild.CustomerID)
End If

I cant just paste this code anywhere. Do I make a Public sub to paste this code or is there another way. I just want to start reading data from subform as soon as dialog result gets ok

È stato utile?

Soluzione

It depends on how you want to display your sub form. Do you want to display it as a result of a button click? If so, you could put your code into the button click event handler:

Private Sub _showSubFormButton_Click(sender As System.Object, e As System.EventArgs) Handles _showSubFormButton.Click
    Dim frmChild = New SubForm

    If frmChild.ShowDialog = DialogResult.OK Then
        MessageBox.Show("Customer ID: " & frmChild.CustomerID)
    End If
End Sub
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top