Can a data grid in another open form be refreshed by calling a sub routine?
This app has a form with 2 data grids. When the user double click on one of the grids another form is opened that shows data details. After the user changes the details the user clicks a save button.
We have placed this code in the Closing event of the the details form.
Private Sub FormParents_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
FormParentsAndStudents.RefreshDataGrids()
End Sub
The code does execute because we placed a msgbox in there to test it.
Here is the code we are trying to use to refresh the data grids. It's in the form with the 2 data grids:
Public Sub RefreshDataGrids()
Me.ParentsTableAdapter.Fill(Me.DataSetParentsStudents.Parents)
Me.StudentsTableAdapter.Fill(Me.DataSetParentsStudents.Students)
LightGridParents.Refresh()
LightGridStudents.Refresh()
End Sub
Can you tell us what additional coding is needed to refresh this data or if we are using the incorrect place to call this code from within the details form?
I found a way to do it and hope it helps other people.
I removed the call from the details form that refreshed the data grids.
Instead, I call the form as a dialog window when the user double clicks to get the details form. I placed coding after the call to the dialog form to re-fill the table adapter and that did the trick.
Here is the coding:
' Control handlers - Grid handlers.
'----------------------------------
Private Sub LightGrid_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LightGridParents.MouseDoubleClick
If ParentsBindingSource.Count > 0 Then
' Call the parents form.
'-----------------------
objFormParents = New FormParents(IDTextBox.Text, "From Parents And Students")
objFormParents.ShowDialog()
' Refresh the data grid.
'-----------------------
Me.ParentsTableAdapter.Fill(Me.DataSetParentsStudents.Parents)
End If
End Sub
Private Sub LightGridStudents_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles LightGridStudents.MouseDoubleClick
If StudentsBindingSource.Count > 0 Then
' Call the students form.
'------------------------
objFormStudents = New FormStudents(StudentsIDTextBox.Text, "From Parents And Students")
objFormStudents.ShowDialog()
' Refresh the data grid.
'-----------------------
Me.StudentsTableAdapter.Fill(Me.DataSetParentsStudents.Students)
End If
End Sub