Suppress CarriageReturn in DataGridView

deepPowdah

New member
Joined
Mar 28, 2008
Messages
1
Programming Experience
10+
I would like to suppress carriage returns entered in a row in a DataGridView and replace it with a tab. This would prevent users from acccidentally moving between rows when entering data.

So far I have been able to suppress the carriage returns but not replace it with a tab. Any ideas about how to do this

Private Sub DataGridView1_KeyDown( ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown

if e.keycode = Keys.Return then
e.SuppressKeyPress = true
End If

End Sub

Thanks for your help
 
VB.NET:
Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
    Handles DataGridView1.KeyDown

    If e.KeyCode = Keys.Enter Then
        e.Handled = True
        Dim i As Integer = DataGridView1.CurrentCell.ColumnIndex + 1
        DataGridView1.CurrentCell = DataGridView1.CurrentRow.Cells(i)
    End If
End Sub

Haven't tried it but it should be close enough. Might be able to just send the tab key after you've marked the Enter as handled.

VB.NET:
SendKeys.Send("{TAB}")
 
Back
Top