简体   繁体   English

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

[英]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 我必须使用基于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 

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. 问题是,当我从'OrderFormFrm' (项目属性设置-启动表单)启动项目表单时,我从Orderform的文本框中获得了价值,而从仪表板启动项目'OrderFormFrm'没有得到。

I need to display the value 'DGVCustomer.Item(1, e.RowIndex).Value' in Order forms text box 'txtCustCode' 我需要在订单表单文本框'txtCustCode'显示值'DGVCustomer.Item(1, e.RowIndex).Value' '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: 您可以在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

On the DGVCustomer_CellContentDoubleClick write this: 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

To call the searchCustomerfrm from OrderFormFrm you'll have this code: 要调用searchCustomerfrmOrderFormFrm你也会有这样的代码:

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 将一个名为sendingForm的公共属性添加到您的searchCustomerFrm类中

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 最后,设置发送表单的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