2012-11-09 67 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