Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1052
  • Last Modified:

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.
0
sandya_116
Asked:
sandya_116
  • 2
  • 2
1 Solution
 
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
 
jpaulinoCommented:
In VB.NEt you can do in the KeyDown Event

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

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
 
jpaulinoCommented:
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now