当前位置: 动力学知识库 > 问答 > 编程问答 >

How to get value of Dialog Form to form behined in VB.Net

问题描述:

I have windows application form on which i have Lookup (Search Form) which popups as Dialog Form on top of first Form. Through this dialog form's search value I want to see results in form behind. Like when I enter some search text in Dialog Form and click Find Button that Dialog form will close and results will be shown on form behind. Result can be shown in DropDown combo or grid or any control.

But the main thing is to get value from Dialog Form to Form behind.

网友答案:

One easy way to accomplish this is to have the Find button simply hide the form. Then you can expose the result as a public property of the form and finally the calling routine can close and unload the form when it has gotten the result.

In the calling form...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim SelectorDialog As New myDialog
    SelectorDialog.ShowDialog()
    Dim result As String = SelectorDialog.Result()
    SelectorDialog = Nothing
    'do something with the result

End Sub

In your dialog form...

Private formResult As String

Public Function Result() As String
    Return formResult
End Function

Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click
    formResult = "some result"
    Me.Hide()
End Sub

This is an easy way. You can also wrap the whole thing up in a class as well.

网友答案:

Could you use InputBox ? This pops up a modal dialog with a textbox and returns the entered string.

网友答案:

You could pass it as a parameter to a subroutine in the other form

分享给朋友:
您可能感兴趣的文章:
随机阅读: