【发布时间】:2015-06-16 09:49:12
【问题描述】:
我为此创建了一个 datagridview 和一些文本框 我想如果一个人在选定的 ro 中输入相应的值,则应在表单的文本框中填写相应的值。
我当前的代码提供给我,但它在 cellclick 事件中,但我在按下 enter 键事件中需要它。
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
【问题讨论】:
-
DGV确实有KeyDown、KeyUp和KeyPress事件。你试过这些吗? -
我试过但没有得到解决方案。
-
显示代码怎么样,也许有什么不对的地方我们可以看看。
-
If e.KeyCode = Keys.Enter And DataGridView1.CurrentCell.RowIndex >= 0 Then e.Handled = True e.SuppressKeyPress = True Dim row As DataGridViewRow row = Me.DataGridView1.Rows(DataGridView1. CurrentCell.RowIndex) iname.Text = row.Cells("Name").Value.ToString
-
不清楚您的代码有什么问题。通过单击标签的编辑链接,将您评论中的代码放入您的问题中。
标签: vb.net datagridview enter