2012-11-09 42 views
0

请确实需要帮助解决此问题...我有2个表单Form1Form2。在Form2我过滤DGV通过Textboxchanged event筛选表单2中的datagridview并将筛选后的数据返回到Form1中的datagridview中

TBC代码

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 

我通过为Form1 DGVDataSource分配dv返回过滤后的数据。

此代码的工作

Form1.TestingDataGridView1.DataSource = dv 

在这里,在我的问题,在Form1(用过滤后的数据)。我想EditdataDGV然后Update我的MySql Table "testing"。我真的很困惑这个原因,我从来没有这样做过。我通常使用ff代码Update my 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 

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

回答

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