Datagrid值显示在错误的位置

时间:2018-03-13 02:53:55

标签: .net database vb.net datagridview datagrid

我有一个datagridview,它显示我数据库中的数据。但是,每当我第一次和第二次单击数据网格时,数据都会显示在指定的文本框中,但经过多次保存和更新后,它将显示在错误的文本框中。在我添加绑定源,数据集和数据表以过滤数据网格后,问题出现了。我无法找到问题所在,因为它没有提示任何错误。

这是datagridview的代码

 Private Sub forreviewdatagrid_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles forreviewdatagrid.CellClick

    Dim row As DataGridViewRow = forreviewdatagrid.CurrentRow

    Try
        cmbboxcateg.Text = row.Cells(0).Value.ToString()
        DateTimePickerForReview.Text = row.Cells(1).Value.ToString()
        txtbrandname.Text = row.Cells(2).Value.ToString()
        txtprodname.Text = row.Cells(3).Value.ToString()
        txtproddesc.Text = row.Cells(4).Value.ToString()
        txtcolor.Text = row.Cells(5).Value.ToString()
        txtodor.Text = row.Cells(6).Value.ToString()
        txttaste.Text = row.Cells(7).Value.ToString()
        txttexture.Text = row.Cells(8).Value.ToString()
        txtform.Text = row.Cells(9).Value.ToString()
        txtshelflife.Text = row.Cells(10).Value.ToString()
        txtpackmat.Text = row.Cells(11).Value.ToString()
        txtdescofprod.Text = row.Cells(12).Value.ToString()
        txtstoragereq.Text = row.Cells(13).Value.ToString()
        txtdirforuse.Text = row.Cells(14).Value.ToString()
        txtfuncfoodmat.Text = row.Cells(15).Value.ToString()
        txtallergen.Text = row.Cells(16).Value.ToString()
        txtlotcode.Text = row.Cells(17).Value.ToString()
        txtopendate.Text = row.Cells(18).Value.ToString()
        txttypefoodprod.Text = row.Cells(19).Value.ToString()
        txtprodrisk.Text = row.Cells(20).Value.ToString()
        txtprodcateg.Text = row.Cells(21).Value.ToString()

      Catch ex As Exception

    End Try

End Sub

这是过滤datagridview的代码

 Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

    Dim pistableadapter As New MySqlDataAdapter("Select * From pis, pis2 WHERE productid=productidrev", MysqlConn)

    Dim pistable As New DataTable()

    pistableadapter.Fill(dt)
    pisBindingSource.DataSource = dt
    pisBindingSource.Filter = "prodname = '" & txtsearch.Text & "' "
    forreviewdatagrid.DataSource = pisBindingSource


End Sub

0 个答案:

没有答案