I am using visualstudio 2005, with a datagridview that has 1 row and 7 columns.
I am trying to make it so that when the user enters data in the last cell and hits enter that the data is committed by exiting the cell, but the datagridview is not recognising that the enter key is being pressed.
The datagridview is not bound to a datatable, and the datatable is updated by the user pressing a button.
I have the following handler written for editcontrolshowing:
If Me.DataGridView1.CurrentCell.ColumnIndex = 6 Then
Dim tb As TextBox = CType(e.Control, TextBox)
AddHandler tb.KeyPress, AddressOf DataGridView1_KeyPress
This is to use e.handled in keypress to restrict entry to numbers, decimal point etc..
then under keypress before the e.handled line :
If Me.DataGridView1.CurrentCell.ColumnIndex = 6 AndAlso e.KeyChar = _
Me.DataGridView1.CurrentCell = Me.DataGridView1(0, 0)
The keypress is not recognising that the enter key is being pressed. If I change the key to a number or letter then it does recognise the keypress and moves to cell Me.DataGridView1(0, 0).
I have tried the following, but it still does not work:
Capturing the enter key through keydown with e.KeyCode
Removing all aother code in keypress, other than the enter capture
Enabling Keypreview on the form
Coding acceptreturn = true
Changing the cell from edit on enter to edit on F2
Using return instead of enter
Using the ascii character
Changing control focus
I have noted that is does not recognise the tab key either, but this is not a problem because the tabkey exits the cell and commits the data.
I have tried:
If e.KeyCode = Keys.Return AndAlso Me.DataGridView1.CurrentCell.ColumnIndex = 6 Then
This does not work, again because the return key press is not recognised.
Does any one have any ideas please?