Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Should be easy - Filling a List box across forms

I have process where I am getting the information from form1 and passing items to form2...not an issue there.  Then when I am done with form2, I want to repopulate a Listbox from SqlServer with the data that I just added in Form2.  I only want this repopulation to occure when I close form2.

Here is the Form2 code

...
Private WithEvents frmMain As frm_Main
Private Sub btn_AddPar_p_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_AddPar_p.Click
...
                GetConnection()
                SqlCon.Open()

                ' Refresh Parent Varaible List
                Dim sqlcom2 As SqlCommand = New SqlCommand("SELECT Parents " & _
                                    "FROM Recode_Parent " & _
                                    "WHERE Recodes ='" & txt_Recode_p.Text & "'", SqlCon)
                Dim reader_parent As SqlDataReader
                reader_parent = sqlcom2.ExecuteReader
                frmMain.lst_Parents1.Items.Clear()
                While reader_parent.Read
                    frmMain.lst_Parents1.Items.Add(reader_parent("Parents"))
                End While
                reader_parent.Close()

                ' Close Open Items
                SqlCon.Close()

I am trying to access item in frm_Main
0
tobey1
Asked:
tobey1
  • 2
1 Solution
 
rspahitzCommented:
Not sure that I understand right, but

In form 2 add a method like this:

    Friend Function GetClosingData()
        Dim strReturnData As String
        strReturnData = "this is the data you wanted"
        Return strReturnData
    End Function

When form2 closes, intercept it in form1:

    Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Form2s.Closing
        MessageBox.Show(Form2.GetClosingData())
    End Sub
0
 
rspahitzCommented:
just curious...was this a C-grade because it was a bad answer?

Please explain since I could have probably given a better answer with more feedback...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now