将表单1中的信息传递到表单2未正确显示

时间:2016-05-03 07:30:13

标签: vb.net

我正在尝试将表单1对象中的信息传递给表单2对象。我得到的只是表格2上的空白屏幕。

这是我到目前为止所拥有的

表格1上的

我有:

    Option Strict On

Public Class frmElevatedResults

    Public Property val As Object

    Private Sub frmElevatedResults_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'This Load event displays the results of the elevated cholestoral levels above 200.  
        lstResults = CType(val, ListBox)

在表格2上我有:

*** Variables ***

${PORT}     36504
${HOST}     https://staging-product..co/api/products
${HeaderName}     Content-Type
${HeaderValue}     application/json
${HeaderName1}     Authorization
${HeaderValue1}     Token token=zkzg1VPnhcMm7uv,email=cctest7@gmail.com


*** Settings ***

Resource        variables.txt
Library         HttpLibrary.HTTP
Test Setup      Create HTTP Context  ${HOST}    https

*** Test Cases ***
Set Headers
    POST      https://staging-product..co/api/products

Full-URL GET to MytestSsite
    GET      https://staging-product.connect.co/

我已经在这几个小时了。如果有人能让我知道为什么表格2中的列表框是空白的,我将不胜感激。

2 个答案:

答案 0 :(得分:1)

我在此假设lstHighCholesterol不是empty,也是ListBox控件。您的Form 1代码已经正确无误。试试这个:

Public Class frmElevatedResults
     Public val as New ListBox

     Private Sub frmElevatedResults_Load(sender As Object, e As EventArgs) Handles MyBase.Load
           For Each itm in val.Items
               lstResults.Items.Add(itm)
           Next
     End Sub
...

答案 1 :(得分:0)

试试这个解决方案: 在form2上添加一个构造函数:

 Public Property val As Object
Public Sub New(val As Object)
    InitializeComponent() ' This call is required by the Windows Form Designer.
    Me.val=val
End Sub


    Private Sub frmElevatedResults_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'This Load event displays the results of the elevated cholestoral levels above 200.  
        lstResults = CType(val, ListBox)

在form1中:

 Private Sub btnTestResults_Click(sender As Object, e As EventArgs) Handles btnTestResults.Click
    Dim obb As New frmElevatedResults(lstHighCholesterol)
    obb.Show( )