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.
rrowe68Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jorge PaulinoIT Pro/DeveloperCommented:
You can change the EditMode property
 
Ex.

Me.DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter
 
Aaron JabamaniTechnical ArchitectCommented:
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
omegaomegaDeveloperCommented:
Hello, rrowe68,
If it's appropriate, you can also do this at design time.  Click on the "..." beside Collection in the Properties list and choose the appropriate column.  Click the "..." beside the DefaultCellStyle property to open the "CellStyle Builder".  Then choose "True" for WrapMode".

Your users will then be able to enter a line break into the cell.  But note that to do this they must hold the <Shift> key down while striking the <Enter> key.   (It may be possible to capture the <Enter> key and translate it to <Shift><Enter> in a keyboard event, but I haven't tried this.)

Cheers,
Randy

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrowe68Author Commented:
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.Message, 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 DataGridViewTextBoxEditingControl) Then
                    SendKeys.Send("+~")
                    Return True
                End If
            End If
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.