从数据表格中传递数据到表单,反之亦然。

问题描述 投票:0回答:1

我有一个名为 "FrmClientesEdicion "的表单,其中有一个邮政编码字段,我试图打开邮政编码文件,并将第二个表单中选择的信息从数据网格返回到第一个表单。发生的事情是,到目前为止,信息没有传递给我,而是打开了一个新的实例的形式 "FrmClientesEdicion",帮助?

  1. 从 "FrmClientesEdicion "中的一个按钮打开邮政编码表格 "FrmCodigosPosAr",其中有一行。

        Dim f As New FrmCodigosPosAr
    f.ShowDialog()
    
  2. 在表格中搜索:"FrmCodigosPosAr",选择一行,然后再把数据(如代码,姓名)传给第一行。"FrmClientesEdicion "中的这行。

    Try
        Dim F As New FrmClienteEdicion
        With F
            .TxtCPOCLI.Text = DG.CurrentRow.Cells(0).Value.ToString ' The code
            .TxtPOBCLI.Text = DG.CurrentRow.Cells(1).Value.ToString ' The name city
            .TxtPROCLI.Text = DG.CurrentRow.Cells(2).Value.ToString ' The state
        End With
    Catch ex As Exception
        MsgBox("Verifique: " & ex.Message.ToString, MsgBoxStyle.Critical)
    End Try
    Me.Close()
    

这第二点不工作打开一个新的实例,但不`......再次感谢注:第一个表单仍然打开,当我打开第二个表单时从未关闭它!图片。

打开第2个表格然后再将数据从FORM2传递到FORM1 AGAIN。

datagrid
1个回答
0
投票

我回答自己的情况下,有人需要它

  1. 在form2 (FremCodigosPosAr)中。

    Public Class FrmCodigosPosAr
    Inherits System.Windows.Forms.Form
    Public myCaller As FrmClienteEdicion
    
  2. 在表格1中,(例如,在按钮中调用表格2(FrmCodigosPosAr))。

        Dim myform As FrmCodigosPosAr
    Private Sub BtnBuscaCP_Click(sender As Object, e As EventArgs) Handles BtnBuscaCP.Click
    If myform Is Nothing Then
        myform = New FrmCodigosPosAr
        myform.myCaller = Me
    End If
    myform.Show()
    

    结束子

  3. 在表格2(FrmCodigosPosAr)中,将数据传递给表格1(FrmClientesEdicion)

        Try
        If Not myCaller Is Nothing Then
            myCaller.Text = Now.ToLongTimeString
            myCaller.TxtCPOCLI.Text = DG.CurrentRow.Cells(0).Value.ToString
            myCaller.TxtPOBCLI.Text = DG.CurrentRow.Cells(1).Value.ToString
            myCaller.TxtPROCLI.Text = DG.CurrentRow.Cells(2).Value.ToString
        End If
    Catch ex As Exception
        MsgBox("Verifique: " & ex.Message.ToString, MsgBoxStyle.Critical)
    End Try
    Me.Close()
    
© www.soinside.com 2019 - 2024. All rights reserved.