我现在终于可以更新数据视图了……让我在这里发布我的代码以供将来参考,以防万一有人也需要帮助。这是一个示例项目,所以我没有深入研究代码,而是直接讨论了我是如何解决它的。
Form1
拥有Datagridview(databound), 1 button "Form2"
表格 1 的代码
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
`TODO: This line of code loads data into the TestDataSet.testing table. You can move, or remove it, as needed.`
Me.TestingTableAdapter.Fill(Me.TestDataSet.testing)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
' Me.Hide()'
Me.TestingBindingSource.DataSource = TestDataSet
Me.TestingTableAdapter.Dispose()
Me.TestingTableAdapter.Fill(Me.TestDataSet.testing)
End Sub
Private Sub TestingDataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles TestingDataGridView1.CellEndEdit
If MsgBox("Save Changes Made in this Cell?", MsgBoxStyle.YesNo, MsgBoxStyle.Exclamation) = DialogResult.Yes Then
Me.Validate()
Form2.TestingBindingSource().EndEdit()
Me.TestingTableAdapter.Update(Me.TestDataSet.testing)
End If
End Sub
End Class
Form2
拥有DGV (databound), 2Buttons, "Return", "Save", and a textbox
Private Sub TestingBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestingBindingNavigatorSaveItem.Click
Me.Validate()
Me.TestingBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.TestDataSet)
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the TestDataSet.testing table. You can move, or remove it, as needed.'
Me.TestingTableAdapter.Fill(Me.TestDataSet.testing)
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim tableAdapter As New testDataSetTableAdapters.testingTableAdapter
Dim ds As New testDataSet
dv.Table = TestDataSet.testing
dv.RowFilter = "CONVERT(TransactionID, System.String) LIKE '%" & TextBox1.Text & "%'"
TestingDataGridView.DataSource = dv
Form1.TestingDataGridView1.DataSource = dv
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.Show()
Me.Hide()
Me.TestingTableAdapter.Dispose()
Me.TestingTableAdapter.Fill(Me.TestDataSet.testing)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MsgBox("Save Changes Made in this Cell?", MsgBoxStyle.YesNo, MsgBoxStyle.Exclamation) = DialogResult.Yes Then
Me.Validate()
Me.TestingBindingSource.EndEdit()
Me.TestingTableAdapter.Update(Me.TestDataSet.testing)
End If
End Sub