rrowe68
asked on
How to include the 'Return' in the editing of a Datagridview cell?
I have a datagridview box that allows a user to edit the contents of the cell. It is a memo field that a user edits and may need to use 'enter' (ie. Return) to go to the next line.
However, when you hit enter, it jumps out to the next cell.
Any way to code it so that the Return acutally stays within the current cell and goes to the next line in the cell?
Thanks.
However, when you hit enter, it jumps out to the next cell.
Any way to code it so that the Return acutally stays within the current cell and goes to the next line in the cell?
Thanks.
You have to capture the key strokes "on change event" of the celland if it is enter key then focus to next line.
Below URL has code snippet.
http://it.gps678.com/5/f0f4c141ed09ec21.html
Below URL has code snippet.
http://it.gps678.com/5/f0f4c141ed09ec21.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I added this and it worked. I captured the Enter Key and replaced it with Shift Enter.
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Messa ge, ByVal keyData As System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Enter Then
Dim ctl As Control = Me.ActiveControl
If Not (ctl Is Nothing) Then
If (TypeOf ctl Is DataGridViewTextBoxEditing Control) Then
SendKeys.Send("+~")
Return True
End If
End If
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Messa
If keyData = Keys.Enter Then
Dim ctl As Control = Me.ActiveControl
If Not (ctl Is Nothing) Then
If (TypeOf ctl Is DataGridViewTextBoxEditing
SendKeys.Send("+~")
Return True
End If
End If
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Ex.
Me.DataGridView1.EditMode = DataGridViewEditMode.EditO