将 Datagridview 列值获取到 Textbox1、Textbox2、Textbox3
Getting Datagridview Column Values to Textbox1, Textbox2,Textbox3
我尝试了这里的所有解决方案。没有什么对我有用。我想获得 a
的值
column("ProductCode")
至
Textbox1, Textbox2,Textbox3....
这是我的全部资料。此代码仅显示所述列第一行的数据。我想要发生的是在显示 "ProductCode"
到 Textbox1
第一行的值之后,它将显示 "ProductCode"
到 Textbox2
第二行的值。谢谢
With DataGridView1
For i As Integer = 0 To .RowCount - 1
Dim x As UInteger
For x = 1 To 12
Me.Controls.Find("TextBox" + CStr(x), False)(0).Text = .Rows(i).Cells(2).Value()
Next
Next
End With
End Sub
假设您有足够的文本框来容纳所有行,您只需要一个 For
循环。如果允许网格添加行,您会注意到网格末尾有一个空行。在这种情况下,您将需要 .RowCount - 2
来计算该额外行。文本框名称将以 i + 1 结尾,因为尽管行以索引 0 开头,但文本框名称结尾以 1 开头。
Private Sub OpCode()
With DataGridView1
For i As Integer = 0 To .RowCount - 2
Me.Controls.Find("TextBox" & CStr(i + 1), False)(0).Text = .Rows(i).Cells(2).Value().ToString
Next
End With
End Sub
我尝试了这里的所有解决方案。没有什么对我有用。我想获得 a
的值 column("ProductCode")
至
Textbox1, Textbox2,Textbox3....
这是我的全部资料。此代码仅显示所述列第一行的数据。我想要发生的是在显示 "ProductCode"
到 Textbox1
第一行的值之后,它将显示 "ProductCode"
到 Textbox2
第二行的值。谢谢
With DataGridView1
For i As Integer = 0 To .RowCount - 1
Dim x As UInteger
For x = 1 To 12
Me.Controls.Find("TextBox" + CStr(x), False)(0).Text = .Rows(i).Cells(2).Value()
Next
Next
End With
End Sub
假设您有足够的文本框来容纳所有行,您只需要一个 For
循环。如果允许网格添加行,您会注意到网格末尾有一个空行。在这种情况下,您将需要 .RowCount - 2
来计算该额外行。文本框名称将以 i + 1 结尾,因为尽管行以索引 0 开头,但文本框名称结尾以 1 开头。
Private Sub OpCode()
With DataGridView1
For i As Integer = 0 To .RowCount - 2
Me.Controls.Find("TextBox" & CStr(i + 1), False)(0).Text = .Rows(i).Cells(2).Value().ToString
Next
End With
End Sub