Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

i have one datagrid and i want like when i click on any cell and press enter key, then the control should go to the next cell.
by default it is going to the next row.
and when i press tab it's going to the next cell.

So i want that tab function in enter key

Please tell me how to do..

Thank you
Posted
Comments
Sergey Alexandrovich Kryukov 26-Dec-12 19:08pm    
What is "reagrding"? Not clear what do you want to achieve.
—SA
[no name] 27-Dec-12 0:13am    
I want is by default we have to press tab to go to the next cell of the datagrid..correct..so i want that function in enter button..if we press enter key then it should go to the next cell

1 solution

Your question is quite confusing but I assume you want your gridview to move the cursor/focus to the next cell after pressing the "enter" key instead of going to the next row (in other words, do what the "tab" key).

If that is the case then for me the easiest way to do that is to trap the key in KeyDown event and send the key that you need to be pressed

VB
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.SuppressKeyPress = True
          SendKeys.Send("{TAB}")
      End If
End Sub


This might interfere with other things you need to do but can be adjusted accordingly.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900