Should be easy - Filling a List box across forms

Posted on 2005-05-04
Last Modified: 2010-04-23
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

                ' 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
                While reader_parent.Read
                End While

                ' Close Open Items

I am trying to access item in frm_Main
Question by:tobey1
    LVL 22

    Accepted Solution

    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
        End Sub
    LVL 22

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now