簡體   English   中英

如何返回(移回)具有值的表單

[英]how to go back (move back) to a form with a value

我在查找窗口中遇到了嚴重問題,請幫助解決此問題。

看到我的表單打開的步驟

  1. 打開第一個表單(從儀表板)

     Dim ObjOrder As New OrderFormFrm ObjOrder.USER = USER ObjOrder.Show() 
  2. 接下來,我必須基於文本框事件打開一個彈出窗口。

     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. 我必須使用基於gridview行單擊事件的值返回到Orderform

     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 

問題是,當我從'OrderFormFrm' (項目屬性設置-啟動表單)啟動項目表單時,我從Orderform的文本框中獲得了價值,而從儀表板啟動項目'OrderFormFrm'沒有得到。

我需要在訂單表單文本框'txtCustCode'顯示值'DGVCustomer.Item(1, e.RowIndex).Value' 'txtCustCode'

請幫忙解決這個問題

您可以在searchCustomerfrm表單上創建一個共享函數,該函數返回該表單期望的值:

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

DGVCustomer_CellContentDoubleClick以下內容:

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

    Me.DialogResult = DialogResult.OK

End Sub

要調用searchCustomerfrmOrderFormFrm你也會有這樣的代碼:

txtCustCode.Text = searchCustomerfrm.GetCustomer

除非我錯過了什么,否則您需要通過實例名稱而不是類型來調用原始表單。

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

將一個名為sendingForm的公共屬性添加到您的searchCustomerFrm類中

Public Class searchCustomerFrm
Public sendingForm As OrderFormFrm

然后在創建新表單時將該屬性設置為發送表單

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

最后,設置發送表單的textbox屬性

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM