如何从sa MDI表单Groupbox获取文本框的值?

时间:2014-04-15 16:09:27

标签: vb.net rdlc mdichild mdiparent

我是vb.net的新手并且一直在寻找解决方案。我所涉及的表格是 MainMenu,poCustom和rdlcForm 。所有这些都运行良好,直到我用 MDI表单重新审视。

我的"新" MainMenu现在将poCustom包含在Groupbox中。我将代码搜索为

    For Each f As Form In Application.OpenForms
        If TypeOf f Is poCustom Then
            f.Activate()
            Return
        End If
    Next

    Dim ch As New poCustom
    ch.TopLevel = False
    ch.Visible = True

    ch.StartPosition = FormStartPosition.Manual
    Dim leftStart As Integer = 1220 - (ch.Width + (SystemInformation.Border3DSize.Width * 2))
    Dim topStart As Integer = 670 - (ch.Height + (SystemInformation.Border3DSize.Height * 2))

    ch.Location = New Point(leftStart, topStart)

    GroupBox1.Controls.Add(ch)

问题: rdlcForm(报告)无法获取poCustom表单中文本框的值。代码如下:

 Private Sub rptPOView2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim rptParam1(11) As Microsoft.Reporting.WinForms.ReportParameter
    rptParam1(0) = New Microsoft.Reporting.WinForms.ReportParameter("rptDate", poCustom.Label1.Text)
    rptParam1(1) = New Microsoft.Reporting.WinForms.ReportParameter("rptREF", poCustom.Label5.Text)
    rptParam1(2) = New Microsoft.Reporting.WinForms.ReportParameter("rptCompany", poCustom.CompanyName.Text)
    rptParam1(3) = New Microsoft.Reporting.WinForms.ReportParameter("rptQTY", poCustom.txBoxQTY.Text)
    rptParam1(4) = New Microsoft.Reporting.WinForms.ReportParameter("rptUOM", poCustom.txBoxUOM.Text)
    rptParam1(5) = New Microsoft.Reporting.WinForms.ReportParameter("rptDesciption", poCustom.txBoxDesc.Text)
    rptParam1(6) = New Microsoft.Reporting.WinForms.ReportParameter("rptUnit", poCustom.txBoxUnit.Text)
    rptParam1(7) = New Microsoft.Reporting.WinForms.ReportParameter("rptTotal", poCustom.txBoxTotal.Text)
    rptParam1(8) = New Microsoft.Reporting.WinForms.ReportParameter("rptSubTotal", poCustom.Label25.Text)
    rptParam1(9) = New Microsoft.Reporting.WinForms.ReportParameter("rptVAT", poCustom.Label26.Text)
    rptParam1(10) = New Microsoft.Reporting.WinForms.ReportParameter("rptTotalAmount", poCustom.Label27.Text)
    rptParam1(11) = New Microsoft.Reporting.WinForms.ReportParameter("rptRequest", poCustom.Label30.Text)

    ReportViewer1.LocalReport.SetParameters(rptParam1)
    Me.ReportViewer1.RefreshReport()

    TextBox1.Text = poCustom.CompanyName.Text
End Sub

在不使用MDI表单的情况下工作正常。我想知道问题的原因以备将来使用。提前谢谢!

1 个答案:

答案 0 :(得分:1)

您使用的是poCustom的两个不同实例。 ch是第一个,您填充其文本框。但是在rptPOView2_Load事件中,您正在使用另一个实例,其中包含尚无值的文本框。解决问题的一种方法是使用poCustom本身,而不是ch

poCustom.TopLevel  = False
poCustom.Visible = True

poCustom.StartPosition = FormStartPosition.Manual
Dim leftStart As Integer = 1220 - (ch.Width + (SystemInformation.Border3DSize.Width * 2))
Dim topStart As Integer = 670 - (ch.Height + (SystemInformation.Border3DSize.Height * 2))

poCustom.Location = New Point(leftStart, topStart)

GroupBox1.Controls.Add(poCustom)