Vb.net 单击“下一步”按钮,在文本框中显示要更新的新值

Vb.net 单击“下一步”按钮,在文本框中显示要更新的新值,vb.net,Vb.net,在下面的代码中,我希望按钮7用作下一个按钮。此按钮获取查询结果并将其显示在文本框描述中。现在,由于同一查询有多个描述,我希望在单击按钮时在datagridview中显示下一个描述 Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click Dim conn5 As MySqlConnection conn5 = New MySqlConnection conn5.Con

在下面的代码中,我希望按钮7用作下一个按钮。此按钮获取查询结果并将其显示在文本框描述中。现在,由于同一查询有多个描述,我希望在单击按钮时在datagridview中显示下一个描述

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    Dim conn5 As MySqlConnection
    conn5 = New MySqlConnection
    conn5.ConnectionString = "server=127.0.0.1;userid=dec;password=xVdRs84825uhLZtb;database=dec"
    Dim sda5 As New MySqlDataAdapter
    Dim dbdataset5 As New DataTable
    Dim bsource5 As New BindingSource
    Try
        conn5.Open()
        Dim command As New MySqlCommand
        ' Dim sqlquery As String = "SELECT comment FROM bh_status WHERE jobid = '" & jobid & "';"
        Dim sqlquery As String = "SELECT item_code,description,unit,quantity,material_cost,labour_cost,total_material_cost,total_labour_cost FROM ht_33kv_list_qty where project_id = '" & prj_id & "';"
        command = New MySqlCommand(sqlquery, conn5)
        sda5.SelectCommand = command
        sda5.Fill(dbdataset5)
        bsource5.DataSource = dbdataset5
        DataGridView4.DataSource = bsource5
        sda5.Update(dbdataset5)
        conn5.Close()
        Dim i As Integer = 0
        For i = 0 To DataGridView4.RowCount - 1

            Dim cell As DataGridViewCell = DataGridView1(3, i)
            Description.Text = cell.Value


        Next
    Catch ex As Exception

    End Try
End Sub
要在描述文本框中显示DataGridView1第3列中所有单元格的值(通过单击按钮7一次显示一个),可以执行以下操作:

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
    With Me.DataGridView1
        Dim NextRow = .CurrentRow.Index + 1
        If NextRow >= .Rows.Count Then
            NextRow = .Rows.Count - 1   ' If you need a cycle then using ─────> NextRow = 0
        End If
        .CurrentCell = Me.DataGridView1(.CurrentCell.ColumnIndex, NextRow)
    End With
End Sub

Private Sub DataGridView1_CurrentCellChanged(sender As Object, e As System.EventArgs) Handles DataGridView1.CurrentCellChanged
    With Me.DataGridView1
        If .CurrentCell IsNot Nothing Then
            Me.Description.Text = Me.DataGridView1(3, .CurrentCell.RowIndex).Value.ToString
        End If
    End With
End Sub

你要什么还不完全清楚。您是说您有一个数据库中的多条记录显示在DataGridView中,其中一条记录也显示在一个或多个文本框控件中,并且您希望能够更改文本框中显示的记录吗?请尝试使用计数器,这样第一次单击时,您的计数器将增加。不要忘记在例行程序结束时重置计数器。