如何在多个文本框中显示来自同一数据库vb.net的多条记录



my vb采购单输出

问题是,我想在每个文本框中选择不同的产品,但两个文本框中的值是相等的,我不能单独添加。由于学校的一个项目,我刚开始接触vb。我真的希望有一个解决方案。我需要在3个文本框中显示3个值,但目前我只在2个文本框内尝试过。我希望这能解释

这是我为数据库编写的文本框输出代码:

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim row As DataGridViewRow = DataGridView1.CurrentRow
Try
txtprod1.Text = row.Cells(1).Value.ToString()
txtPrice.Text = row.Cells(2).Value.ToString()
txtqty.Text = row.Cells(3).Value.ToString()
Catch ex As Exception
yLoad()
End Try
Try
txtprod2.Text = row.Cells(1).Value.ToString()
txtprice2.Text = row.Cells(2).Value.ToString()
txtqty2.Text = row.Cells(3).Value.ToString()
Catch ex As Exception
yLoad()
End Try
End Sub
Private Sub DataGridView1_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
If Not IsLoaded Then
Exit Sub
End If
Static CurrentCount As Integer
If CurrentCount < 3 Then
CurrentCount += 1
Else
CurrentCount = 1
End If
Dim s As String = DataGridView1.Rows(e.RowIndex).Cells(1).Value.ToString
'Cell 1 happens to be the Name property in the grid I am using
Select Case CurrentCount
Case 1
TextBox1.Text = s
Case 2
TextBox2.Text = s
Case 3
TextBox3.Text = s
Case Else
MessageBox.Show("Error")
End Select
'CurrentRow is a day late and a dollar short when using the RowEnter event
'Dim s As String = DataGridView1.CurrentRow.Cells(1).Value.ToString
End Sub
Dim IsLoaded As Boolean = False
Private Sub DataGridViewTest_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
IsLoaded = True
End Sub

IsLoaded Form级别(类级别(变量会阻止选择发生,直到您更改选择。

静态变量将在对Sub.的调用之间保持其值

If语句跟踪Sub被调用的次数,这样我们就知道要填写什么文本框。

我们通过使用DataGridViewCellArgs(e(和RowIndex属性来获得我们想要的单元格。您可以用其他单元格值再设置几个变量,然后将它们分配给选定情况下的文本框。

最新更新