Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thank you in advance for your help.
I am opening ESTIMATESEARCH from REPAIRS and getting a record ID from a grid on ESTIMATESEARCH. I then store this value in a text box on REPAIRS and close ESTIMATESEARCH
My problem is the VB code on ESTIMATESEARCH does not process until after the calling code on REPAIRS completes so the data I want isn't there... yet.
I have read several solutions in this website and one or more may work but but they are in C# so I'd have to convert just to find out. I may be wrong but would think this is a simple solution. I used to program in VB6 years ago and have just started with VB.NET a month ago.

What I have tried:

Form 1 code
Private Sub SearchEstimatesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SearchEstimatesToolStripMenuItem.Click
    EstimateSearch.Show()
    If SearchBox.Text > "" Then
        'look for this string

    End If
End Sub


Form2 code
Private Sub EstGrid_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles EstGrid.CellDoubleClick
     Dim MCol = e.ColumnIndex
     Dim MRow = e.RowIndex
     Dim CurrentRow As Integer
     CurrentRow = EstGrid.CurrentRow.Index
     If CurrentRow >= 0 Then
         Repairs.SearchBox.Text = EstGrid.Rows(CurrentRow).Cells(0).Value
         Me.Close()
     End If
 End Sub
Posted
Updated 14-Jan-19 2:21am

Use ShowDialog instead of Show:
Private Sub SearchEstimatesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SearchEstimatesToolStripMenuItem.Click
    EstimateSearch.ShowDialog()
    If SearchBox.Text > "" Then
        'look for this string

    End If
End Sub
That way, your parent form "waits" for the newform to close before the code continues.

But ... you should check if the user closed it positively (using an OK button) or negatively (using a Cancel button) by checking the Dialog Result, and "ask the form" for the value:
VB
If EstimateSearchBox.ShowDialog = DialogResult.OK Then
   string result = EstimateSearchBox.Result
   ...
End If
And provide a Property in the dialog which returns the text box content.
 
Share this answer
 
v2
In addition to solution #1 by OriginalGriff[^], i'd suggest to read about these methods to understand the differences between them:
Form.Show(IWin32Window) Method (System.Windows.Forms) | Microsoft Docs[^] - shows the form as a non-modal dialog box.
Form.Show(IWin32Window) Method (System.Windows.Forms) | Microsoft Docs[^] - shows the form as a modal dialog box.

To be able to achieve what OG mentioned, you have to set a DialogResult Property (System.Windows.Forms) | Microsoft Docs[^] of 'OK' and 'Cancel' button placed on a ESTIMATESEARCH form. For further details, please see: How to use the DialogResult property in Visual Basic .NET or in Visual Basic 2005[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900