Miranda Lynn Miranda Lynn - 7 months ago 20
Vb.net Question

Passing information from form 1 to form 2 is not displaying correctly

I am trying to pass the information from form 1 object to form 2 object. all I am getting is a blank screen on form 2.

here is what I have so far

on form 1 I have :

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


On form 2 I have:

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)


I have been at this for hours. Please if anyone can give me an idea of why the list box in form 2 is blank, I would appreciate it.

Answer

I assume here that lstHighCholesterol is not empty and is also a ListBox control. Your Form 1 code is already correct. Try this:

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
...
Comments