Solved

Datagridview move cursor to right

Posted on 2014-10-17
4
116 Views
Last Modified: 2014-10-24
Hi
I am trying to move the cursor to right in the grid when ENTER key is pressed.
My Code
 
Private Sub DataGridParts_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridParts.KeyDown

        If e.KeyCode = Keys.Enter Then
         
                e.SuppressKeyPress = True
                Dim iCol = DataGridParts.CurrentCell.ColumnIndex
                Dim iRow = DataGridParts.CurrentCell.RowIndex
            If iCol = 9 Then
                        DataGridParts.CurrentCell = DataGridParts(0, iRow + 1)
                    Else
                        DataGridParts.CurrentCell = DataGridParts(iCol+1, iRow)
              End If
       
     end if
end sub
It works fine as long as you don not change any cell value.
If I change the cell text and then when ENTER key pressed it goes down to next row instead going to right in the sale row.

Please help
0
Comment
Question by:b001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:louisfr
ID: 40387237
Use the PreviewKeyDown event to tell the control Enter must be processed as an input key:
private void DataGridParts_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    switch (e.KeyCode)
    {
        case Keys.Enter:
            e.IsInputKey = true;
            break;
    }
}

Open in new window

0
 

Author Comment

by:b001
ID: 40388048
Hi losisfr

please convert the above code for  VB Basic
Thanks
0
 

Author Comment

by:b001
ID: 40388049
I mean Visual Studio Basic
0
 
LVL 11

Accepted Solution

by:
louisfr earned 500 total points
ID: 40388987
Sorry, here:
Private Sub DataGridParts_PreviewKeyDown(sender As Object, e As PreviewKeyDownEventArgs) Handles DataGridParts.PreviewKeyDown
    Select case e.KeyCode
        Case Keys.Enter
            e.IsInputKey = true
    End Select
End Sub

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question