I have a window in VB.net which contains data from a table in SQL Server using an sqladaptor. The user has an option to add data to the table by clicking a button and selecting the source data. The question is, how do I refresh the data in the listbox to reflect the addition of the data?
The data is added by opening another form. I thought that I could refresh the data by reflling the dataset by calling the getfocus. However, this does not refresh the data and teh only way I have succeeded in seeing the new data is by physically closing the form at runtime and then reloading it. The code I have for refreshing the data is:
Private Sub FillDataSetAnd View()
objAdaptor = Nothing
objAdaptor = New SqlDataAdaptor("Select identifier, CI Type, FilePath FROM dbo.usr_importfilepaths", objConnection)
objDataSet = New DataSet
lstFilePaths.DataSource = objDataView
lstFilePaths.DisplayMember = "CIType"
I've tried adding this on the GotFocus and the Load events for the form. However, these do not seem to fire, mainly because the form will not close. Ideally I'd like the form to close when the add new data button is selected, but I can't seem to get this to work.
I have a private sub in the gorm called ExitForm() which empties all variables and has Me.Close() as the final line. This does not close the form however! I've tried several methods of closing the form, including having code to close the form as part of the code on the button which calls the next form:
'Call next form and close this form
Dim frmAddCITypes as Form
frmAddCITypes = frmAddCI 'This calls the code at the top of the frmAddCI form under Public Class
ExitForm() 'private sub to close existing form
Because I can't get the first form to close correctly I can't call the load event on the first form when the data has been successfully added. What is the best way of closing one form, launching the next form or indeed updating a dataset to show additions?