Link to home
Start Free TrialLog in
Avatar of sandya_116
sandya_116

asked on

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.
Avatar of Shanmuga Sundaram D
Shanmuga Sundaram D
Flag of India image

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
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sandya_116
sandya_116

ASKER

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.
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
Thanks. That worked perfectly.