Link to home
Start Free TrialLog in
Avatar of tobey1
tobey1Flag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...