我已经创建了一个datagridview和一些文本框 我想如果一个人点击进入选定的ro,相应的值应该填写在表格的文本框中。
我当前的代码提供了我,但它在cellclick事件中,但我需要在按下输入键事件。
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
iname.Text = row.Cells("Name").Value.ToString
icode.Text = row.Cells("Item code").Value.ToString
irate.Text = row.Cells("Rate").Value.ToString
icomnt.Text = row.Cells("Comment").Value.ToString
End If
End Sub
答案 0 :(得分:0)
私有子 DataGridView1_KeyPress(sender As Object, e As KeyPressEventArgs) 处理 DataGridView1.KeyPress
If e.KeyChar = ChrW(Keys.Enter) Then
DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.CurrentRow.Index - 1).Cells(0)
txtno.Text = DataGridView1.SelectedCells(0).Value
End If
End Sub