datagridview disable tab

How can I disable the user from pressing tab in a datagridview or when user presses tab, I don't want the selection to move from the current row to the new row. Thanks.
sandya_116Asked:
Who is Participating?
 
Jorge PaulinoIT Pro/DeveloperCommented:
In VB.NEt you can do in the KeyDown Event

If e.KeyCode = Keys.Tab Then
  e.Handled = True
End If

0
 
Shanmuga SundaramDirector of Software EngineeringCommented:
Hi Sandya,

If you want to disable the user from pressing tab in a datagridview or when the user presses tab, if you don't want the selection to move from the current row to the new row then in the keypress event of the datagridview reset the keyascii value of the tab key to 0. For example

Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
      If KeyAscii = 9 Then KeyAscii = 0
End Sub

Hope this might help you.

by
D.Shanmuga Sundaram
0
 
sandya_116Author Commented:
Thanks jpaulino. That worked. I don't know if I have to open a new post but how can I disable the user from pressing down and up arrows in the grid as I just want the rows to b highlighted only when user clicks on a cell.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
You can do it in the same way. Please confirm the Keys.Up and Keys.Down because right now I cannot test it.

If e.KeyCode = Keys.Tab or e.KeyCode = Keys.Down or e.KeyCode = Keys.Up Then
  e.Handled = True
End If
0
 
sandya_116Author Commented:
Thanks. That worked perfectly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.