This question has already been asked several times but none found an answer.
我需要覆蓋datagridview上的Enter鍵,以便它不會跳轉到下一行,但允許我將輸入的文本保存到數據庫。這需要在用戶輸入文本框時完成。覆蓋keydown在datagridview上輸入
使用:作爲ENTER鍵並不在文本框細胞火
Private Sub DataGridView1_mt_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1_mt.KeyDown
If e.KeyCode = Keys.Enter Then
...
將無法正常工作。 Keyup可以工作,但由於程序已經跳到下一個單元,所以它遲到了。按鍵與Keydown有同樣的問題。
任何關於如何檢測輸入鍵的按鍵並覆蓋它的想法?
UPDATE: 如果選中一個單元格,我可以檢測到Enter鍵,但如果我正在輸入文本框,則不能檢測到Enter鍵。 (其實我需要的是檢測當用戶完成然後按回車。
Private Sub DataGridView1_EditingControlShowing(sender As System.Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1_mt.EditingControlShowing
Dim tb As TextBox = CType(e.Control, TextBox)
AddHandler tb.KeyDown, AddressOf TextBox_KeyDown
End Sub
Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return Then
MessageBox.Show("Success") '''''DOES NOT WORK
End If
If e.KeyCode = Keys.Space Then
MessageBox.Show("Success") '''''WORKS
End If
End Sub
已經嘗試過,它不工作.. Keydown根本沒有觸發,無論我檢查什麼密鑰 – user2452250
看到的代碼,並嘗試 –
更新我的問題與額外的信息 – user2452250