0

请在这方面我真的需要帮助...我有 2 个表格Form1Form2. 在Form2我过滤DGV依据Textboxchanged event

待定代码

Dim dvSection As DataView
    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

dv我通过将 分配为新DataSource的 for 来返回过滤后的数据Form1 DGV

此代码有效

    Form1.TestingDataGridView1.DataSource = dv

在我的问题中,在Form1(带有过滤数据)中。我想Editdata里面DGV然后Update我的MySql Table "testing"。我对此感到非常困惑,因为我以前从未这样做过。Update我通常使用 ff 代码DGVMySql Table在这种情况下,ff 代码如何不起作用。

 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

我现在真的很困惑,有点帮助会非常好。谢谢,麻烦您了。

4

1 回答 1

0

我现在终于可以更新数据视图了……让我在这里发布我的代码以供将来参考,以防万一有人也需要帮助。这是一个示例项目,所以我没有深入研究代码,而是直接讨论了我是如何解决它的。

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
于 2012-11-09T03:51:21.900 回答