简体   繁体   中英

how to go back (move back) to a form with a value

I am facing a serious issue with a lookup window, Please help to solve this.

see the steps of my form opens

  1. Opens first form (from Dashboard)

     Dim ObjOrder As New OrderFormFrm ObjOrder.USER = USER ObjOrder.Show() 
  2. Next I have to open a popwindow based on a textbox event.

     Private Sub txtCustCode_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtCustCode.MouseClick Dim PopUpCustomer As New searchCustomerfrm PopUpCustomer.ShowDialog() End Sub 
  3. I have to goback to Orderform with a value based on a gridview row click event

     Private Sub DGVCustomer_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCustomer.CellContentDoubleClick OrderFormFrm.txtCustCode.Text = Val(DGVCustomer.Item(1, e.RowIndex).Value)` Me.Close() End Sub 

The problems is, I am getting value to Orderform's textbox when I start project form from 'OrderFormFrm' (project properties setting-start form), and not getting if I started project from the dashboard.

I need to display the value 'DGVCustomer.Item(1, e.RowIndex).Value' in Order forms text box 'txtCustCode'

Please help to solve this

you could make a shared function on the searchCustomerfrm form that returns the value that you expect from the form:

Public Shared Function GetCustomer()
      Dim PopUpCustomer As New searchCustomerfrm
      If PopUpCustomer.ShowDialog() = DialogResult.OK Then
           Return Val(PopUpCustomer.DGVCustomer.Item(1, PopUpCustomer.DGVCustomer.CurrentRow.Index).Value) 
      Else
           Return Nothing
      End If
End Function

On the DGVCustomer_CellContentDoubleClick write this:

Private Sub DGVCustomer_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCustomer.CellContentDoubleClick 

    Me.DialogResult = DialogResult.OK

End Sub

To call the searchCustomerfrm from OrderFormFrm you'll have this code:

txtCustCode.Text = searchCustomerfrm.GetCustomer

Unless I missed something, you need to be calling the original form by instance name and not by type...

Private Sub DGVCustomer_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCustomer.CellContentDoubleClick

    ObjOrder.txtCustCode.Text = Val(DGVCustomer.Item(1, e.RowIndex).Value)

Me.Close()

End Sub

add a public property called sendingForm to your searchCustomerFrm class

Public Class searchCustomerFrm
Public sendingForm As OrderFormFrm

Then set that property to the sending form when you create the new form

Private Sub txtCustCode_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtCustCode.MouseClick 

    Dim PopUpCustomer As New searchCustomerfrm
    PopUpCustomer.sendingForm = Me
    PopUpCustomer.ShowDialog()
End Sub

Finally, set the textbox property of the sending form

Private Sub DGVCustomer_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCustomer.CellContentDoubleClick


        sendingForm.txtCustCode.Text = Val(dgvCustomer.Item(1, e.RowIndex).Value)

        Me.Close()

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM